Question: Here a C program that is using the UNIX system. #include #include #include #include #include #define BUFLEN 10 int main(void) { int i; char buffer[BUFLEN+1];

Here a C program that is using the UNIX system. #include

#include

#include

#include

#include

#define BUFLEN 10

int main(void)

{

int i;

char buffer[BUFLEN+1];

pid_t fork_return;

fork_return = fork( );

if (fork_return == 0)

{

strncpy(buffer, "CHILD ", BUFLEN); /*in the child process*/

buffer[BUFLEN] = '\0';

}

else if(fork_return > 0)

{

strncpy(buffer, "PARENT ", BUFLEN); /*in the parent process*/

buffer[BUFLEN] = '\0';

}

else if(fork_return == -1)

{

printf("ERROR: ");

return 1;

}

for (i=0; i

{

sleep(1); /*5 times each*/

write(1, buffer, strlen(buffer));

}

return 0;

}

The output will like like

Here a C program that is using the UNIX system. #include #include

IMP: One process will always end before the other. If there is enough intervening time before the second process ends, the system call will redisplay the prompt, producing the last line of output where the output from the child process is appended to the end of the prompt (ie. %child)

You know that the wait() system call allows the parent process to suspend its activities until one of these actions has occurred.

Need to write and explain :

  1. Explain the functioning of this program
  2. insert a wait() system call to change the output to:

#include #include #include #define BUFLEN 10 int main(void) { int i; char Paste it in this comment with changing code and explain what difference it has made to the program.

  1. There is another system call clone(). How is it different than fork()?
  2. Process Control Block is the information about each process? What is the data structure required to maintain this information?

[comp23100@cs2 - ] $ ./a.out PARENT CHILD PARENT CHILD PARENT CHILD PARENT CHILD CHILD PARENT [comp23100@c32 ~]$ ./a.out CHILD CHILD CHILD CHILD CHILD PARENT PARENT PARENT PARENT PARENT

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!