#include int write(int,char*,int); int read(int,char*,int); int fork(void); int kill(int,int); /* save this file as sample.c and do cc sample.c */ int main() { int pid,i,j,stat,ppid; char c; write(1,"prog starts\n Please type a char and press ENTER\n",48); printf("my id (original process's id= %d\n",getpid()); if ((pid=fork())==0) { /* child code */ write(1,"Child executing\n",16); printf("Child: Parent's pid = %d\n",getppid()); for(i=0;i<150000;i++){ {for (j=0; j<4000000; j++); write(1,"Child ",6);} /* keep writing till killed by parent */ }} else { /* parent code */ write(1,"parent executing\n",17); write(1,"Parent:Really want to kill ?",28); for(i=0;i<15;i++){ for (j=0; j<4000000; j++); write(1,"parent ",7);} /* keep writing till killed by parent */ read(0,&c,1); /* wait for user to type something and enter key before we go about killing the child */ i=kill(pid,SIGKILL); /* send SIGKILL to the process with id = pid, which is the child */ wait(&stat); printf("Parent:Value of stat is %d\n",stat); /* wait for child to terminate. */ printf("Parent:value of i is %d\n",i); i=kill(pid,SIGINT); /* sending signal to a terminted process; should get return value of -1 (see man pages of kill()) */ printf("Parent:value of i is %d\n",i); write(1,"parent terminating\n",19); } }