Related Content: CS604 - VU Lectures, Handouts, PPT Slides, Assignments, Quizzes, Papers & Books of Operating Systems
We discussed in detail the UNIX/Linux directory structure in lecture 4. We will continue that discussion and learn how to browse the UNIX/Linux directory structure. In Figure 5.1, we have repeated for our reference the home directory structure for students. In the rest of this section, we discuss commands for creating directories, removing directories, and browsing the UNIX/Linux directory structure.
You can display the contents (names of files and directories) of a directory with the ls command. Without an argument, it assumes your current working directory. So, if you run the ls command right after you login, it displays names of files and directories in your home directory. It does not list those files whose names start with a dot (.). Files that start with a dot are known as hidden files (also called dot files). You should not modify these files unless you are quite familiar with the purpose of these files and why you want to modify them. You can display all the files in a directory by using ls –a command. Your can display the long listing for the contents of a directory by using the ls –l command. The following session shows sample runs of these commands.
$ ls
books courses LinuxKernel chatClient.c chatServer.c
$ ls -a
. .bash_history courses .login .profile
.. .bash_profile .cshrc books
chatClient.c chatServer.c LinuxKernel
$ ls –l
drwxr-xr-x 3 msarwar faculty 512 Oct 28 10:28 books
-rw-r--r-- 1 msarwar faculty 9076 Nov 4 10:14 chatClient.c
-rw-r--r-- 1 msarwar faculty 8440 Nov 4 10:16 chatServer.c
drwxr-xr-x 2 msarwar faculty 512 Feb 27 17:21 courses
drwxr-xr-x 2 msarwar faculty 512 Oct 21 14:55 LinuxKernel
$
The output of the ls –l command gives you the following information about a file:
We will talk about file types and hard links later in the course.
You can use the mkdir command to create a directory. In the following session, the first command creates the courses directory in your current directory. If we assume that your current directory is your home directory, this command creates the courses directory under your home directory. The second command creates the cs604 directory under the ~/courses directory (i.e., the under the courses directory under your home directory). The third command creates the programs directory under your ~/courses/cs604 directory.
$ mkdir courses
$ mkdir ~/courses/cs604
$ mkdir ~/courses/cs604/programs
$
You could have created all of the above directories with the mkdir –p ~/courses/cs604/programs command.
You can remove (delete) an empty directory with the mkdir command. The command in the following session is used to remove the ~/courses/cs604/programs directory if it is empty.
$ rmdir courses
$
You can jump from one directory to another (i.e., change your working directory) with the cd command. You can use the cd ~/courses/cs604/programs command to make ~/courses/cs604/programs directory your working directory. The cd or cd $HOME command can be used to make your home directory your working directory.
You can display the absolute pathname of your working directory with the pwd command, as shown below.
$ pwd
/home/students/nadeem/courses/cs604/programs
$
We now discuss the commands to copy, move (or rename), and remove files.
You can use the cp command for copying files. You can use the cp file1 file2 command to copy file1 to file2. The following command can be used to copy file1 in your home directory to the ~/memos directory as file2.
$ cp ~/file1 ~/memos/file2
$
You can use the mv command for moving files. You can use the mv file1 file2 command to move file1 to file2. The following command can be used to move file1 in your home directory to the ~/memos directory as file2.
$ mv ~/file1 ~/memos/file2
$
You can use the rm command to remove files. You can use the rm file1 command to remove file1. You can use the first command the following comman to remove the test.c file in the ~/courses/cs604/programs directory and the second command to remove all the files with .o extension (i.e., all object files) in your working directory.
$ rm ~/courses/cs604/programs/test.c
$ rm *.o
$
You can compile your program with the gcc command. The output of the compiler command, i.e., the executable program is stored in the a.out file by default. To compile a source file titled program.c, type:
$ gcc program.c
$
You can run the executable program generated by this command by typing./a.out and hitting the <Enter> key, as shown in the following session.
$ ./a.out
[ ... program output ... ]
$
You can store the executable program in a specific file by using the –o option. For example, in the following session, the executable program is stored in the assignment file.
$ gcc program.c –o assignment
$
The gcc compiler does not link many libraries automatically. You can link a library explicitly by using the –l option. In the following session, we are asking the compiler to link the math library with our object file as it creates the executable file.
$ gcc program.c –o assignment -lm
$ assignment
[ ... program output ... ]
$
A process can be thought of as a program in execution. A process will need certain
resources – such as CPU time, memory, files, and I/O devices – to accompany its task.
These resources are allocated to the process either when it is created or while it is
executing.
A process is the unit of work in most systems. Such a system consists of a collection
of processes: operating system processes execute system code and user processes execute
user code. All these processes may execute concurrently.
Although traditionally a process contained only a single thread of control as it ran,
most modern operating systems now support processes that have multiple threads.
A batch system executes jobs (background processes), whereas a time-shared system
has user programs, or tasks. Even on a single user system, a user may be able to run
several programs at one time: a word processor, web browser etc.
A process is more than program code, which is sometimes known as the text section.
It also includes the current activity, as represented by the value of the program counter
and the contents of the processor’s register. In addition, a process generally includes the
process stack, which contains temporary data (such as method parameters, the process
stack, which contains temporary data), and a data section, which contains global
variables.
A program by itself is not a process: a program is a passive entity, such as contents of
a file stored on disk, whereas a process is an active entity, with a program counter
specifying the next instruction to execute and a set of associated resources. Although two
processes may be associated with the same program, they are considered two separate
sequences of execution. E.g. several users may be running different instances of the mail
program, of which the text sections are equivalent but the data sections vary.
Processes may be of two types:
As a process executes, it changes states. The state of a process is defined in part by the current activity of that process. Each process may be in either of the following states, as shown in Figure 5.2:
Each process is represented in the operating system by a process control block (PCB) – also called a task control block, as shown in Figure 5.3. A PCB contains many pieces of information associated with a specific process, including these:
The objective of multiprogramming is to have some process running all the time so as to maximize CPU utilization. The objective of time-sharing is to switch the CPU among processors so frequently that users can interact with each program while it is running. A uniprocessor system can have only one running process at a given time. If more processes exist, the rest must wait until the CPU is free and can be rescheduled. Switching the CPU from one process to another requires saving of the context of the current process and loading the state of the new process, as shown in Figure 5.4. This is called context switching.
As shown in Figure 5.5, a contemporary computer system maintains many scheduling queues. Here is a brief description of some of these queues:
In the queuing diagram shown in Figure 5.6 below, each rectangle box represents a queue, and two such queues are present, the ready queue and an I/O queue. A new process is initially put in the ready queue, until it is dispatched. Once the process is executing, one of the several events could occur:
A process migrates between the various scheduling queues throughout its lifetime. The
operating system must select, for scheduling purposes, processes from these queues in
some fashion. The appropriate scheduler carries out this selection process. The Longterm
scheduler (or job scheduler) selects which processes should be brought into the
ready queue, from the job pool that is the list of all jobs in the system. The Short-term
scheduler (or CPU scheduler) selects which process should be executed next and
allocates CPU.
The primary distinction between the two schedulers is the frequency of execution.
The short-term scheduler must select a new process for the CPU frequently. A process
may execute for only a few milliseconds before waiting for an I/O request. Often the
short-term scheduler executes at least once every 100 milliseconds. Because of the brief
time between executions, the short-term scheduler must be fast. If it takes 10
milliseconds to decide to execute a process for 100 milliseconds, then 10/(100+10)=9 %
of the CPU is being used for scheduling only. The long-term scheduler, on the other hand
executes much less frequently. There may be minutes between the creations of new
processes in the system. The long-term scheduler controls the degree of
multiprogramming – the number of processes in memory. If the degree of
multiprogramming is stable, then the average rate of process creation must be equal to the
average department rate of processes leaving the system. Because of the longer interval
between execution s, the long-term scheduler can afford to take more time to select a
process for execution.
The long-term scheduler must select a good mix of I/O bound and CPU bound jobs.
The reason why the long-term scheduler must select a good mix of I/O bound and CPU
bound jobs is that if the processes are I/O bound, the ready queue will be mostly empty
and the short-term scheduler will have little work. On the other hand, if the processes are
mostly CPU bound, then the devices will go unused and the system will be unbalanced.
Some operating systems such as time-sharing systems may introduce a medium-term
scheduler, which removes processes from memory (and from active contention for the
CPU) and thus reduces the degree of multiprogramming. At some later time the process
can be reintroduced at some later stage, this scheme is called swapping. The process is
swapped out, and is later swapped in by the medium term scheduler. Swapping may be
necessary to improve the job mix, or because a change is memory requirements has over
committed available memory, requiring memory to be freed up. As shown in Figure 5.7,
the work carried out by the swapper to move a process from the main memory to disk is
known as swap out and moving it back into the main memory is called swap in. The area
on the disk where swapped out processes are stored is called the swap space.