Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

and here is paid1

image text in transcribed

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

What is electric dipole explain with example

Answered: 1 week ago