Presentation is loading. Please wait.

Presentation is loading. Please wait.

Operating System Concepts and Techniques Lecture 3 Process M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First ed.,

Similar presentations


Presentation on theme: "Operating System Concepts and Techniques Lecture 3 Process M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First ed.,"— Presentation transcript:

1 Operating System Concepts and Techniques Lecture 3 Process M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First ed., iUniverse Inc., 2011. To order: www.iUniverse.com, www.barnesandnoble.com, or www.amazon.comwww.iUniverse.comwww.barnesandnoble.comwww.amazon.com

2 2 Process Process: born to run programs Inside a computer there is a little society of processes; Processes are born, live, and die Operating system is the governing body of processes It must keep information about processes, called process attributes, to be able to manage them

3 Some attributes 3 Process identification information Process ID Parent process User identifier Group identifier Process state information Process-visible registers Location counter Condition code flags Stack pointers Process control information Status Priority Process start time CPU time used Children’s CPU time used Scheduling parameters Links Process privileges Memory pointers Devices assigned to the process Open files Flags

4 Process Control Block (PCB) Process attributes are kept in an operating system structure called PCB; One for each process There is one process table in the system Each row is for one process; it either has all PBC information of the process or some of it and a pointer to the PCB; the latter is our convention When process is terminated its PCB is removed 4

5 Process table 5 Properties of P 1 blocked Properties of P 2 ready Properties of P 3 blocked Properties of P 4 running Properties of P 5 ready Properties of P 6 ready Properties of P 7 blocked Properties of P 8 ready Properties of P 9 ready Properties of P 10 blocked Process properties State Link Link to PCB Front of ready queue Rear of ready queue

6 System calls Kernel is robust, fault-free, and efficient It includes numerous useful procedures Some we can call from application programs, these are called system calls, supervisor calls, or kernel services Kernel is protected from outside world, entering and leaving is via an strict controlled mechanism. 6

7 Breaking into kernel 7 … call a kernel service from an application program …. Other layers of the operating system A kernel service Kernel Barrier Kernel AB Kernel barrier is busted twice as shown at points A and B Although a kernel routine is used by an application program, it is like taking a prisoner to an outside hospital for medical services while handcuffed and accompanied by two guards

8 Some system calls 8 Process Management pid = fork() pid = waitpid (pid, &static, options) s = execve (name, argv, envp) exit (status) s = kill (pid, sig) pause () wait (&status) alarm (sec) Interprocess Communication qid = msgget(queueid, rights) msgsnd(qid, &mymsg, size, flags) msgrcv(qid, &mymsg, size, type, flags) semid = semget(key, nsems, rights) semop( semid, operation) File System fd = create (name, mode) fd = open (file, how) s = close (fd) n = read (fd, buffer, nbytes) n = write (fp, buffer, nbytes) pos = lseek (fd, offset, whence) s = stat (name, &buf) s = mkdir (path, mode) s = rmdir (path) s = unlink (name) s = chdir (name) s = chmode (name, mode)

9 Unix Process State Transition Model 9 UNIX States The corresponding state in the 3-stae model Ready to Run Swapped Ready to Run in Memory Preempted Sleep SwappedAsleep In Memory User Running Created Zombie Kernel Running Ready Wait/ Blocked Running Process birth Interrupt, Interrupt return A process is picked to run Memory needed, swap out Running obstacle is vanished Preempt System call or interrupt Return Not enough main memory Main memory assigned Sleep condition ended Exit, but not disappeared Imaginary line Back to running Needs I/O or circumstance Memory shortage swap out Swap in

10 Why are Processes Created? Processes are the means of running programs to perform tasks Processes are created from executable files 10

11 When is a Process Created? At computer start or restart, by OS Explicit request by a computer user double clicking on an executable file opening an executable program file issuing a command to run a program, etc. In response to a request from a running process to create a child process 11

12 Process creation/termination Why are processes created? When is a process created? What is done to create a process? What are the tools for creating a process? What are common in parent and child processes? What are different between parent and child processes? How is a process terminated? 12

13 What is done to create a process? Ensure the degree of multiprogramming does not been exceeds its maximum Generate a unique process ID Use one row of Process table Allocate space for the PCB and initialize proper fields; then make the connection between the corresponding row of the process table and this PCB Allocate space for process context Allocate space for other preliminary structures such as stacks and stack pointers and initialize the related fields in PCB Put the process in one of the queues, usually ready queue 13

14 Process creation using fork() void main(void) { int pid; int retval; int status; // Pointer to the value returned by the child process pid = fork(); // It is assume that, there is no obstacle in creating // the child process if (pid != 0) // This is the parent process { proc1; // Parent process will continue running procedure proc1 wait (&status); // Wait until the child process is terminated } else { proc2; // Child process will continue running procedure proc2 status = …; // Provide a valid value for the returned status to parent process exit (status); } 14

15 How is a Process Terminated? When its execution is completed it is logically terminated For the physical termination of a process, all memory occupied as process images and stacks are first freed. Then, the process control block is freed and the process is removed from the process table Logical termination of a process takes less processing time than its physical termination. For logical termination it suffices to change the terminating process’s state to terminated and to actually add this process to the set of terminated processes. It could be killed by OS or user 15

16 Summary Processes are one of the central issues of every operating system Processes are created to run programs Process state transition diagram shows the living states of process and its transactions The request to create a process could come from a user, an application process, or the operating system itself The same requesters could order the destruction of a process or it could be terminated automatically when its duty is finished or when a fatal fault has occurred A process that requests the creation of another process becomes the parent process and the created process is called the child process A child process goes its own way right after it is created As UNIX is a process-based operating system, this chapter was able to use actual examples from this operating system. 16

17 17 Find out The purpose of system calls The purpose of the transitions from kernel to itself Complete set of Unix system calls The deficiencies of process How we can create a child process to run a different program (not a different procedure) Whether Linux is a process-based operating system or a thread-based one

18 18 Any questions?


Download ppt "Operating System Concepts and Techniques Lecture 3 Process M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First ed.,"

Similar presentations


Ads by Google