Sunday 26 July 2015

ABOUT PROGRAM 3 theory IN RECORD:


fork():-
to create a new process from a program we use fork().the prototype of fork() is 
    pid_t fork();

.
*)function fork() causes the unix system to create a new process known as child process with                new process id.

*)the contents of child process are identical to contents of parent process.

*)entire address space of parent process is duplicated for child process.

*)all the statements after fork() are executed in both parent and child.

*)fork() returns '0' in child process and nn zero in parent process.
exec():-
*)the unique system call that transforms an executable binary file into a process or the exec family of systems
 i.e;   from a program by calling either of these functions we can load an executable file of a program into address space of current process.

wait():
The system call wait() is easy. This function blocks the calling process until one of its child processes exits or a signal is received. 
For our purpose, we shall ignore signals. wait() takes the address of an integer variable and returns the process ID of the completed process. 
Some flags that indicate the completion status of the child process are passed back with the integer pointer. One of the main purposes of wait() is to wait for completion of child processes.
The execution of wait() could have two possible situations.
  1. If there are at least one child processes running when the call to wait() is made, the caller will be blocked until one of its child processes exits. At that moment, the caller resumes its execution.
  2. If there is no child process running when the call to wait() is made, then this wait() has no effect at all. That is, it is as if no wait() is there.

exit():

The function _exit() terminates the calling process "immediately".

 Any open file descriptors belonging to the process are closed; any children of the process are inherited by process 1, init, and the process's parent is sent a SIGCHLD signal.

The value status is returned to the parent process as the process's exit status, and can be collected using one of the wait(2) family of calls.

The function _Exit() is equivalent to _exit().





No comments:

Post a Comment