Question: I am pasting my code . and also attach output . please don't use Chatgpt I need real code . I just want to fix
I am pasting my code and also attach output please don't use Chatgpt I need real code I just want to fix my code according to the required output. I attached mine output and required output.I am getting first output correct but second and third is not correct. Write a C program where child processes are forked in this way:
the original process creates two child processes
each process created from the original process creates two child processes
Each process is given a unique process number in range in this way:
the original process is numbered
the two processes created by process are numbered and
the two processes created by process are numbered and
the two processes created by process are numbered and
Your program receives arguments from command line. These arguments are expected
to be natural numbers. You do not need to handle wrong inputs. Each process will go to
sleep for some time after having created child processes if needed. The number of
seconds a process numbered i is put to sleep is the ith argument.
The sleep time can be considered the simulation of the different computation time each
process takes to carry out its subtask.
Before each process terminates, print out its process number and process id#include
#include
#include
#include
#include
void forkprocessint processnumber, int sleeptime
pidt pid fork;
if pid
fprintfstderr "Fork Failed";
exit;
else if pid
Child process
sleepsleeptime;
printfprocess d terminated. pidd
processnumber, getpid;
exit;
int mainint argc, char argv
if argc
fprintfstderr "Usage: s
argv;
return ;
int sleeptimes;
for int i ; i ; i
sleeptimesi atoiargvi ;
printfprocess terminated. pidd
getpid;
sleepsleeptimes;
if fork
forkprocess sleeptimes;
forkprocess sleeptimes;
waitNULL;
waitNULL;
exit;
waitNULL;
if fork
forkprocess sleeptimes;
forkprocess sleeptimes;
waitNULL;
waitNULL;
exit;
waitNULL;
if fork
forkprocess sleeptimes;
forkprocess sleeptimes;
waitNULL;
waitNULL;
exit;
waitNULL;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
