Question: 1. Write a C program to fork a child process with a fork() and print the process id for a child and for a parent
1. Write a C program to fork a child process with a fork() and print the process id for a child and for a parent process using a C library function getpid(). Create an int variable that should be incremented by a child process and decremented by a parent process. Print the value of the variable for both a child and a parent. 1 Note: a child process id upon returning from fork() is 0. 2. Run a program, comment on the received ids and the values of the variable. Explain. 3. Trace system calls used by your program using strace nameofyourfile (-c option gives a summary of system calls only) 4. Identify a system call responsible for creation of your child process. 5. Modify your program so that your child process creates a thread with the pthread_create call. In a function that a thread will execute print the thread id using the pthread_self() call. 6. Submit your program and explanation.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
