Monday, September 20, 2010

Unix Process Management

                Every process has a process identification number that is used as the index to the process table. The Unix operating system provides a number of system calls for process management. The fork system call is used to create an identical copy of a process. The created process is called the child process and the original process is called as the parent process.

The exit( ) system call is called by a process that wants to terminate itself and leave a status to its parent. Inter-process synchronization can be achieved as follows. A parent process can get blocked using the wait system call until the termination of one of its child process. Signals are used to inform a process about the occurrence of an event. The kernel handles the signals in the context of the process that receive the signal by executing a routine called as the signal handler. The exec system call and its variation are used to execute another program by passing the arguments and environmental variables. The nice system call can be used by a process to control their scheduling priority. The following system calls allocreg, attachreg, growreg, loadreg, freereg, detachreg are used for memory management.

Example  for fork() in c programming


#include
#include
#include
#include


using namespace std;

int main() {
                int pid;
                pid=fork();

                if(pid==-1)
                {
                                printf("\nCant fork the process");
                                exit(1);
                }
                else if(pid== 0)
                {
                                printf("\nI am in Child Process:");
                }
                else
                {
                                printf("\nI am in Parent Process:");
                }

                return 0;
}

No comments:

Post a Comment