Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

debugg hw 2 _ q 9 . c: In function 'main': hw 2 _ q 9 . c: 2 2 : 1 1 : warning:

debugg
hw2_q9.c: In function 'main':
hw2_q9.c:22:11: warning: missing terminating " character
22| printf ("Process %d failed to fork!
", getpid());
hw2_q9.c:22:11: error: missing terminating " character
22| printf ("Process %d failed to fork!
", getpid());
hw2_q9.c:23:3: error: expected expression before 'return'
23| return 1;
hw2_q9.c:23:12: error: expected 'i' before '
code:
//WaitChild.c
#include
#include
#include
int main()
{
pid_t pid;
int status;
pid = fork();
if (pid ==0)
{
printf ("I am process %d", getpid ());
printf (" and my parent is %d.
", getppid ());
}
else if (pid >0)
{
printf ("I am parent %d", getpid ());
printf (" and my child is %d.
", pid);
}
else
{
printf ("Process %d failed to fork!
, getpid());
return 1;
}
printf ("I am process %d.
", getpid());
if (pid ==0)
{
sleep (5); //sleep 5 seconds
printf ("I am process %d", getpid());
printf (" and I quit.
");
}
else
{
printf ("I am parent %d", getpid());
printf (" and I'm waiting for child %d.
", pid);
wait(&status);
printf ("I am parent %d", getpid());
printf (" and my child %d", pid);
printf (" has arrived. I quit too.
");
}
return 0;
}
image text in transcribed

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

Privacy In Statistical Databases International Conference Psd 2022 Paris France September 21 23 2022 Proceedings Lncs 13463

Authors: Josep Domingo-Ferrer ,Maryline Laurent

1st Edition

3031139445, 978-3031139444

More Books

Students also viewed these Databases questions