Question: Notice that when you run pids2, the Child process often thinks its parent has PID=1 whereas in pids1, the Child knew its parent's real PID.

Notice that when you run pids2, the Child process often thinks its parent

has PID=1 whereas in pids1, the Child knew its parent's real PID.

Why?

here is Pids2

Notice that when you run pids2, the Child process often thinks its

and here is paid1

parent has PID=1 whereas in pids1, the Child knew its parent's real

#define GNU_SOURCE 1/for Ubuntu #include #include #include int main (void) { int pid, fpid, ppid; fpid = fork (); printf ("fpid is is $d ", fpid); sleep (5); if (fpid > 0) { pid getpid(); ppid getppid(); printf (" This is Parent. My pid $d. My parent's pid $d ", pid, ppid); } else if (fpid == 0) { sleep(1); pid = getpid(); ppid getppid(); printf (" This is Child. My pid $d. My parent's pid %d ", pid, ppid); } else { printf ("fork failed "); } return (0); } #define _GNU_SOURCE //for Ubuntu #include #include #include int main (void) { int pid, fpid, ppid; fpid fork (); pid getpid(); ppid = getppid(); printf ("fpid is is 8d ", fpid); sleep (5); == if (fpid > 0) { printf(" This is Parent. My pid $d. My parent's pid %d ", pid, ppid); } else if (fpid 0) { sleep(1); printf(" This is Child. My pid $d. My parent's pid $d ", pid, ppid); } else { printf ("fork failed "); } return (0); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!