Starting from:

$30

CPE434-Lab 2 Processes Solved

A process is an instance of a program. The new process is created by issuing a fork system call. Each process has its own area of memory, protected against modification by other processes. The ​fork ​system call creates a copy of a process that was executing. The process that executed the fork is called the ​parent ​process and the new process is called the ​child ​process. . The only difference in the returns from the fork system call is that the return value in the parent process is the process id of the newly created child process, while the return value in the child process is zero. If the fork is not successful, -1 is returned. 

A process terminates by calling the ​exit ​system call. This system call never returns to the caller. When exit is called, an integer exit status is passed by the process to the kernel. 

Exercises 
Write a program that does the following in the order given below:declare and initialize a variable named ​val ​(initialize to 0)
call fork system call
in the child process, add 2 to the value of ​val​, and print it on the console screen along with the pid of the child in the same statement.
in the parent process, add 5 to the value of ​val​, and print it on the console screen along with the pid of the parent process in the same statement.
What can you conclude about the values of the variable ​val​?
Write a program, which creates a new process ​child1​. The parent process should print its id and wait for the termination of the ​child1 ​ The ​child1 ​process should call a function that subtracts two numbers passed as arguments, print the result on the console screen along with the pid of the process that is printing. It should then create a new child ​child2 process that adds two numbers. The control should then come back to the first child process ​child1 ​that now should multiply two numbers and then terminate. The waiting parent process should now resume and terminate the program .
Write a program, which creates n child processes and prints their process id. The n must be an even number and passed as argument, otherwise a message indicates that the number is odd and terminates the program. Please make sure that your implementation has one parent process and n-1 child processes.
Write a C program that demonstrates the concept of following:Orphan Process
Zombie Process
Sleeping Beauty Process
Verify that you actually achieved all the three states mentioned above by using the terminal. Put a screenshot of the process table in your report.
 

Topics for Theory 
Define and discuss the following: process, states of processes, orphan process, and zombie process. Additionally, write a paragraph on each of the functions mentioned in the hint (fork(), exit(), and wait()).

More products