Lab 2: Introduction to Processes Objective: In this lab, you will gain hands-on experience with fundamental concepts of processes in Linux, including process creation
Lab 2: Introduction to Processes Objective: In this lab, you will gain hands-on experience with fundamental concepts of processes in Linux, including process creation using fork() and retrieving process IDs using getpid() and getppid()). Background Information: . The fork() system call returns 0 to the child process to indicate that it has successfully forked from the parent. The parent process receives the PID of the child or -1 if the child did not fork successfully. .getpid() Function: The getpid() function is used to retrieve the Process ID (PID) of the current process. It returns the PID as an integer. .getppid() Function: The getppid(0) function is used to retrieve the PID of the parent process. In a child process, calling getppid(0) will return the PID of the parent process. Task: Process Creation and PID Retrieval Instructions: 1. Create a new C program called process_creation.c. You may want to use this: #include #include #include int main() { *** return 0; 2. Write the C code to create a child process. The parent process must display its PID and its child PID. The child process also must display its PID and its parent PID. Note that the parent process needs to call wait function at the end to avoid creating a zombie process. 3. Compile your program using the following command: gcc process_creation.c -o process_creation 4. Run your program using the following command: /process_creation 5. Observe the output of your program. 6. Take a screenshot of the terminal showing the program's output. 7. Upload the following to Canvas: Your process_creation.c source code file. The screenshot of the program's output. Conclusion: In this lab, you embarked on a practical journey into the world of processes within a Linux environment. You delved into fundamental concepts surrounding processes, honing your skills in process creation and PID retrieval using fork()), getpid(), and getppid(). Lab 2: Introduction to Processes Objective: In this lab, you will gain hands-on experience with fundamental concepts of processes in Linux, including process creation using fork() and retrieving process IDs using getpid() and getppid()). Background Information: . The fork() system call returns 0 to the child process to indicate that it has successfully forked from the parent. The parent process receives the PID of the child or -1 if the child did not fork successfully. .getpid() Function: The getpid() function is used to retrieve the Process ID (PID) of the current process. It returns the PID as an integer. .getppid() Function: The getppid(0) function is used to retrieve the PID of the parent process. In a child process, calling getppid(0) will return the PID of the parent process. Task: Process Creation and PID Retrieval Instructions: 1. Create a new C program called process_creation.c. You may want to use this: #include #include #include int main()) { *** return 0; 2. Write the C code to create a child process. The parent process must display its PID and its child PID. The child process also must display its PID and its parent PID. Note that the parent process needs to call wait function at the end to avoid creating a zombie process. 3. Compile your program using the following command: gcc process_creation.c -o process_creation 4. Run your program using the following command: /process_creation 5. Observe the output of your program. 6. Take a screenshot of the terminal showing the program's output. 7. Upload the following to Canvas: Your process_creation.c source code file. The screenshot of the program's output. Conclusion: In this lab, you embarked on a practical journey into the world of processes within a Linux environment. You delved into fundamental concepts surrounding processes, honing your skills in process creation and PID retrieval using fork(), getpid(), and getppid().
Step by Step Solution
There are 3 Steps involved in it
Step: 1
processcreationc code include include include int main pidt parentpid childpid Fork a child processc...See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started