Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PART-I Question 1 : Given below is a C program that is using UNIX system calls. #include #include #include #include #include #define BUFLEN 10 int

PART-I

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)

Question 2. What is a foreground process and a background process?? What are the roles of following commands? Test them and paste the example in the document. (6 marks)

  • ps
  • kill
  • fg
  • bg
  • &

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_2

Step: 3

blur-text-image_3

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

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions

Question

Coffee or tea?

Answered: 1 week ago