Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 : Given below is a C program that is using UNIX system calls. #include #include #include #include #include #define BUFLEN 10 int main(void)

Question 1 : Given below is a C program that is using UNIX system calls.

#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<5; ++i) /*both processes do this*/

{

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

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

}

return 0;

}

When you run this program, it will print

  • 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.

TODO : (10 marks)

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

Paste it in this document and explain what difference it has made to the program.

  1. There is another system call clone(). How is it different than fork()?

  1. Process Control Block is the information about each process? What is the data structure required to maintain this information? (research and answer)

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

Database Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions