Question: This is coded on a linux operating system, use system calls whenever possible. I know there is a limit to the questions you can do

 This is coded on a linux operating system, use system callswhenever possible. I know there is a limit to the questions youcan do so only do question 3. Here is the code from

This is coded on a linux operating system, use system calls whenever possible. I know there is a limit to the questions you can do so only do question 3. Here is the code from part 2:

#include

#include

#include

int main(void) {

pid_t child_pid;

int status;

pid_t wait_result;

child_pid = fork();

if (child_pid == 0)

{

printf("I am a child and my pid = %d ", getpid());

execlp("average", "./average", NULL);

printf("Could not execl file average ");

exit(1);

}

else if (child_pid > 0)

{

printf("I am the parent and my pid = %d ", getpid());

printf("My child has pid = %d ", child_pid);

}

else

{

printf("The fork system call failed to create a new process ");

exit(1);

}

printf("I am a happy, healthy process and my pid = %d ", getpid());

if (child_pid == 0)

{

printf("This code will never be executed! ");

}

else

{

printf("I am a parent and I am going to wait for my child. ");

do {

wait_result = wait(&status);

} while (wait_result != child_pid);

printf("I am a parent and I am quitting. ");

}

return 0;

}

Linux Process Management (Creation and Termination) ective To work with Linux process management system calls and to understand the relations between newly created processes Description Creating a process in modern operating systems usually includes creating a process control block (PCB) and loading an executable image of the program into memory. To be able to pass arguments and return status information between processes, operating systems maintain organizational information that relates processes to each other. When a process terminates, its memory is made available for other processes and its PCB is deallocated Throughout the process lifetime, the OS keeps track of a process by updating the PCB which has many identifying information. This includes the process ID (PID), its parent's ID (PPID), open file descriptors the process's state and values of the CPU registers last time the process ran on the CPU. The PID, isa unique number that identifies the process throughout its lifetime while the PPID is usually used to pass status information from the terminating child process to its parent. PIDs may be reused after a process terminates, but this usually happens after an extended period and/or when the system runs out of numbers to use Linux provides a parent-child relation between processes. A process, considered a parent process, can create new processes, child processes, which can create their own child processes as well. The parent process ideally should wait for its child processes before it terminates so it gets back the return status info from the child processes. Linux provides many system calls to manage processes throughout their lifetime. These include - pid t fork (void) http://man7.org/linux/man-pages/man2/fork.2.html - pid t vfork(void); http://man7 orq/linux/man-pages/man2/vfork.2.html - pid t getpid (void)http://man7. ora/linux/man-pages/man2/getpid. 2.html - pidt getppid (void) - pid t waitpid (pid_t pid, int *wstatus, int options); - unsigned int sleep (unsigned int seconds) //library function htt man7.org/linux/man-pages/man3/sleep.3.html Submission Submit the answers to the questions below in pdf format One compressed file that contains all C and pdf files To get used to system calls please pay attention to the following o Check the success of every system call you use o Make sure a parent process waits for all of its children

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!