Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

fork not printing pid, current _ pid and parent _ pid please help #include #include #include #include int main ( ) { pid _ t

fork not printing pid, current_pid and parent_pid please help #include
#include
#include
#include
int main()
{
pid_t pid;
char *message;
int n;
printf("fork program starting
");
pid = fork();
switch (pid)
{
case -1:
perror("fork failed");
exit(1);
case 0:
message = "This is the child";
n =5;
break;
default:
message = "This is the parent";
n =3;
waitpid(pid, NULL, 0);
break;
}
for (; n >0; n--)
{
printf("%s; pid=%d; current_pid=%d; parent_pid=%d;
",
message, getpid(),(int)getpid(),(int)getppid());
sleep(1);
}
exit(0);
}
ouput should look like this fork program starting
This is the parent; pid=9774; current_pid=9773; parent_pid=365;
This is the child; pid=0; current_pid=9774; parent_pid=9773;
This is the parent; pid=9774; current_pid=9773; parent_pid=365;
This is the child; pid=0; current_pid=9774; parent_pid=9773;
This is the parent; pid=9774; current_pid=9773; parent_pid=365;
This is the child; pid=0; current_pid=9774; parent_pid=9773;
This is the child; pid=0; current_pid=9774; parent_pid=9773;
$ This is the child; pid=0; current_pid=9774; parent_pid=1;
Once your output looks similar to what is shown above change the code to include two more children. This may require additional conditionals. Now, one parent and three children should be executing.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions

Question

Describe effectiveness of reading at night?

Answered: 1 week ago

Question

find all matrices A (a) A = 13 (b) A + A = 213

Answered: 1 week ago