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 1..7 in this way:
- the original process is numbered 1
- the two processes created by process 1 are numbered 2 and 3
- the two processes created by process 2 are numbered 4 and 5
- the two processes created by process 3 are numbered 6 and 7
Your program receives 7 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 fork_process(int process_number, int sleep_time){
pid_t pid = fork();
if (pid 0){
fprintf(stderr, "Fork Failed");
exit(1);
}
else if (pid ==0){
// Child process
sleep(sleep_time);
printf("process %d terminated. pid=%d
", process_number, getpid());
exit(0);
}
}
int main(int argc, char *argv[]){
if (argc !=8){
fprintf(stderr, "Usage: %s
", argv[0]);
return 1;
}
int sleep_times[7];
for (int i =0; i 7; i++){
sleep_times[i]= atoi(argv[i +1]);
}
printf("process 1 terminated. pid=%d
", getpid());
sleep(sleep_times[0]);
if (fork()==0){
fork_process(2, sleep_times[1]);
fork_process(3, sleep_times[2]);
wait(NULL);
wait(NULL);
exit(0);
}
wait(NULL);
if (fork()==0){
fork_process(4, sleep_times[3]);
fork_process(5, sleep_times[4]);
wait(NULL);
wait(NULL);
exit(0);
}
wait(NULL);
if (fork()==0){
fork_process(6, sleep_times[5]);
fork_process(7, sleep_times[6]);
wait(NULL);
wait(NULL);
exit(0);
}
wait(NULL);
return 0;
}
 I am pasting my code . and also attach output .

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!