Professional Documents
Culture Documents
Fork Grep
Fork Grep
Fork Grep
Write programs using the following system calls of UNIX operating system: fork, exec, getpid, exit Aim : To write a C program using the system calls - fork, exec, getpid, exit Algorithm : 1. 2. 3. 4. 5. 6. 7. 8. Start the program Include header files Create a process using system call Check if result of fork is successful if fork() returns a negative value, the creation of a child process was unsuccessful if fork() returns a zero value, the new child process is created Moreover, a process can use function getpid() to retrieve the process ID assigned to this process. Stop the program
Result : Thus the program using the system calls - fork, exec, getpid, exit is executed and verified
SYSTEM CALLS USING FORK,GETPID,EXIT Source Code:#include <stdio.h> main() { int pid,pid1; www.Technicalsymposium.com
pid=fork(); if(pid==-1) { printf(Error in fork); exit(0); } if(pid==0) { pid1=fork(); exit(0); } printf(\n parent id: %d,getppid()); printf(\n Child id : %d,getpid()); }
www.Technicalsymposium.com