






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Browsing directory structure, Useful UNIX commands, Linux commands, Process concept, Process scheduling concepts, Process creation, Process termination, Displaying Directory Contents. Above mentioned are key points of this lecture handout. Virtual University handout for introduction to operating system are in detail and explanatory.
Typology: Study notes
1 / 10
This page cannot be seen from the preview
Don't miss anything!







Operating Systems--[CS-604] Lecture No. 5
Operating Systems Structures, Chapter 4 PowerPoint Slides for Lecture 3
Browsing UNIX/Linux directory structure Useful UNIX/Linux commands Process concept Process scheduling concepts Process creation and termination
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.
Figure 5.1 Home directories for students
Displaying Directory Contents 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
students
ali nadeem munir
personal courses
cs401 cs
…
…
…
…
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: 1 st^ character: type of a file Rest of letters in the 1 st^ field: access privileges on the file 2 nd^ field: number of hard links to the file 3 rd^ field: owner of the file 4 th^ field: Group of the owner 5 th^ field: File size in bytes 6 th^ and 7 th^ fields: Date last updated 8 th^ field: Time last updated 9 th^ field: File name
We will talk about file types and hard links later in the course.
Creating Directories 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/cs $ mkdir ~/courses/cs604/programs $
You could have created all of the above directories with the mkdir –p ~/courses/cs604/programs command.
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
$ ./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: IO bound processes: spend more time doing IO than computations, have many short CPU bursts. Word processors and text editors are good examples of such processes. CPU bound processes: spend more time doing computations, few very long CPU bursts.
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:
New: The process is being created. Running: Instructions are being executed. Waiting: The process is waiting for some event to occur (such as an I/O completion or reception of a signal. Ready: The process is waiting to be assigned to a processor. Terminated: The process has finished execution.
Figure 5.3 Process control block (PCB)
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.
Figure 5.4 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:
Job Queue: As processes enter the system, they are put into a job queue. This queue consists of all processes in the system. Ready Queue: The processes that are residing in main memory and are ready and waiting to execute are kept on a list called the ready queue. This queue is generally stored as a linked list. A ready-queue header contains pointers to the first and final PCBs in the list. Each PCB is extended to include a pointer field that points to the next PCB in the ready queue. Device Queue: When a process is allocated the CPU, it executes for a while, and eventually quits, is interrupted or waits for a particular event, such as completion of an I/O request. In the case of an I/O request, the device may be busy with the I/O request of some other process, hence the list of processes waiting for a particular I/O device is called a device queue. Each device has its own device queue.
Figure 5.5 Scheduling queue
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: The process could issue an I/O request, and then be placed in an I/O queue. The process could create a new sub process and wait for its termination. The process could be removed forcibly from the CPU, as a result of an interrupt, and be put back in the ready queue.
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.
Figure 5.7 Computer system queues, servers, and swapping