Processes in Unix
Processes in Unix
31/01/2004
1/30/2004
Operating Systems
2 types of processes are available System processes(Execute OS code) User processes( Execute user program code). System call is used to transfer from user
1/30/2004
Operating Systems
1/30/2004
Operating Systems
1/30/2004
Operating Systems
process is about to move from Kernel mode to User mode. While the process is running in Kernel mode it may not be preempted. This make UNIX not suitable for real time processing. Process 0 is a special process that is created when the system boots. Process 1 (init process) is the child of Process 0. All the other processes in UNIX has Process 1 as ancestor. All new processes are created under Process 1 (init process).
1/30/2004 Operating Systems 5
Process Description
Elements of process image -- divided into 3 User level context
Process text, Process data, User stack and Shared memory.
Register context
Program counter, Process status registers, stack pointer, general purpose registers
When a process is not running the processor status information is stored in register context area.
1/30/2004 Operating Systems 6
Process status
(text, data, stack) Process size enables OS to know how much space to allocate User identifier
Real user ID -ID of user who is responsible for the process Effective user ID used by process to gain temporary privilege, while the program is being executed as a part of process. Process identifiers ID of the process
1/30/2004 Operating Systems 7
sleep state. When the event occurs, the process is transferred to a ready to run state. Priority used for scheduling Signal enumerates signals send to process but not yet handled. Timers Process execution time, kernel resource utilization, and user set timer used to send alarm signal to a process. P_link pointer to the next link in the ready queue. Memory status indicates the process image is in the main memory or swapped out.
1/30/2004 Operating Systems 8
corresponding to the user area. User identifiers Real & Effective user Ids, used to determine user privileges. Timers Record time that the process spent executing in user mode & kernel mode. Signal handling array For each type of signal defined in the system, indicate how the process will react to receipt of that signal. Control terminal Indicate login terminal for this process, if exist. Error field Record errors encountered during system call.
1/30/2004 Operating Systems 9
Return value Contain result of s/m call I/O parameters Describes amount of data
transfer, the address of the source data array in user space, file offset for I/O. File parameters Current directory & current root describe the file system environment of the process. User file descriptor table Record the file the process has open Limit fields Restrict the size of the process & size of the file it can write. Permission mode field Mask mode settings on files the process creates.
1/30/2004 Operating Systems 10
2 parts 1. Static (Process table entry, User area, Per process region table). 2. Dynamic (Kernel stack) Process table entry contains process control information that is accessible to the kernel to the kernel at all time. So in VM systems all process table entries are maintained in main memory. User area contains additional process control information that is needed by the kernel when it executes in context of a process. It is also used when swapping process to and from the memory. Process reg. table is used by memory management s/m Kernel stack used when the process is executing in kernel mode and contain information that must be saved and restored as procedure calls and interrupts 1/30/2004 occurs. Operating Systems 11
#include <stdio.h> #include <unistd.h> int main(int argc, char *argv[]) { int pid; /* fork another process */ pid = fork(); if (pid < 0) { /* error occurred */ fprintf(stderr, "Fork Failed"); exit(-1); } else if (pid == 0) { /* child process */ execlp("/bin/ls","ls",NULL); } else { /* parent process */ /* parent will wait for the child to complete */ wait(NULL); printf("Child Complete"); exit(0); } }
1/30/2004 Operating Systems
Fork program in C
12
Fork() in UNIX
Allocate slot in the process table for the new
process Assigns a unique process id to the new process Make a copy of the process image of the parent, with the exception of shared memory It increases counters for any files owned by the parent, to reflect that an additional process now also owns these files. It assigns the child process to a ready to run state It returns the ID number of the child to the parent process and a 0 value to the child process. These all works are done in Kernel of parent process.
1/30/2004 Operating Systems 13
1/30/2004
Operating Systems
15
1/30/2004
Operating Systems
16
It does not destroy the proc structure, this is retained till the parent of Pi destroy it. The terminated process is dead but still exists. Hence it is called ZOMBIE process. The exit call also sends signal to the parent of Pi which may be ignored by the parent.
1/30/2004 Operating Systems 17
1/30/2004
Operating Systems
19
avoid race condition). Each interrupt is assigned an interrupt priority level. An interrupt priority level is also assigned to CPU. When an interrupt at priority level l arises, it is handled only if l> CPUs interrupt priority else kept pending till CPUs interrupt priority level assumes a lower value.
1/30/2004 Operating Systems 20
1/30/2004
Operating Systems
22
corresponding to the signal is set to 1 in the proc structure of the destination process. The kernel now determines if the signal is being ignored by the destination process. If not it will makes provision to deliver the signal to the process. If the signal is ignored it remains pending and is delivered when the process is ready to accept it. In UNIX signal remains pending if the process to which it is intended is in block state. The signal would be delivered when the process comes out of the blocked state. Signals are delivered when A process returns from a system call, after a process get unblocked, before a process gets blocked.
1/30/2004 Operating Systems 24
Child process died or suspended Arithmetic fault Illegal instruction tty interrupt (Control C) Kill process Segmentation fault Invalid System call Exceeds CPU limit Exceeds file size limit
Operating Systems 25