Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Operating Systems Design Lab Computer Engineering Department Fall 2023/2024 Lab 02: fork, exec, and wait systems calls Objectives To understand the forking process and the

Operating Systems Design Lab\ Computer Engineering Department\ Fall 2023/2024\ Lab 02: fork, exec, and wait systems calls\ Objectives\ To understand the "forking" process and the "fork" system call,\ To understand the "exec" system call and its variants from the unistd library.\ To understand the "wait" and "waitpid" system calls.\ Prelab\ Read chapter 3 of the textbook.\ Read the manual pages of the following systems calls and functions.\ pid_t fork(void);\ pid_t wait (int

**

status);\ pid_t waitpid(pid_t pid, int *status, int options);\ int execlp(const char *file, const char *arg, ...);\ Experiment\ Write a simple program to print the PID (process ID) and PPID (parent process ID) of the underlying process. Repeat the execution multiple times (from the shell), then answer the following questions:\ (a) Is the PID the same in all runs? Why/why not?\ (b) Is the PPID the same in all runs? Why/why not?\ Hint: use the getpid and getppid systems calls to get the PID and PPID of a process respectively.\ Modify the program in part 1 so that the main process creates a child process, and each of the two processes prints its PID and PPID. The parent process must wait until the child process terminates.\ (a) Verify the parent-child relationship between the two processes.\ Write a program that continuously asks the user to enter a command (with no arguments). When the user enters a command, the program forks a child process to execute it (using execlp) while it waits until the child finishes execution. The program quits when the user enters "exit" as a command.\ Write a program to draw the following process tree. Verify the correctness of your solution using the PIDs and PPIDs of the generated processes.

image text in transcribed
Operating Systems Design Lab Computer Engineering Department Fall 2023/2024 Lab 02: fork, exec, and wait systems calls Objectives 1. To understand the "forking" process and the "fork" system call. 2. To understand the "exec" system call and its variants from the unistd library. 3. To understand the "wait" and "waitpid" system calls, Prelab 1. Read chapter 3 of the textbook. 2. Read the manual pages of the following systems calls and functions. pid_t fork(void); pid_t wait (int *status); pid_t waitpid(pid_t pid, int *status, int options); int execlp(const char *file, const char *arg, ...); Experiment 1. Write a simple program to print the PID (process ID) and PPID (parent process ID) of the underlying process. Repeat the execution multiple times (from the shell), then answer the following questions: (a) Is the PID the same in all runs? Why/why not? (b) Is the PPID the same in all runs? Why/why not? Hint: use the getpid and getppid systems calls to get the PID and PPID of a process respectively. 2. Modify the program in part 1 so that the main process creates a child process, and each of the two processes prints its PID and PPID. The parent process must wait until the child process terminates. (a) Verify the parent-child relationship between the two processes. 3. Write a program that continuously asks the user to enter a command (with no arguments). When the user enters a command, the program forks a child process to execute it (using execlp) while it waits until the child finishes execution. The program quits when the user enters "exit" as a command. 4. Write a program to draw the following process tree. Verify the correctness of your solution using the PIDs and PPIDs of the generated processes. Operating Systems Design Lab Computer Engineering Department Fall 2023/2024 Lab 02: fork, exec, and wait systems calls Objectives 1. To understand the "forking" process and the "fork" system call. 2. To understand the "exec" system call and its variants from the unistd library. 3. To understand the "wait" and "waitpid" system calls, Prelab 1. Read chapter 3 of the textbook. 2. Read the manual pages of the following systems calls and functions. pid_t fork(void); pid_t wait (int *status); pid_t waitpid(pid_t pid, int *status, int options); int execlp(const char *file, const char *arg, ...); Experiment 1. Write a simple program to print the PID (process ID) and PPID (parent process ID) of the underlying process. Repeat the execution multiple times (from the shell), then answer the following questions: (a) Is the PID the same in all runs? Why/why not? (b) Is the PPID the same in all runs? Why/why not? Hint: use the getpid and getppid systems calls to get the PID and PPID of a process respectively. 2. Modify the program in part 1 so that the main process creates a child process, and each of the two processes prints its PID and PPID. The parent process must wait until the child process terminates. (a) Verify the parent-child relationship between the two processes. 3. Write a program that continuously asks the user to enter a command (with no arguments). When the user enters a command, the program forks a child process to execute it (using execlp) while it waits until the child finishes execution. The program quits when the user enters "exit" as a command. 4. Write a program to draw the following process tree. Verify the correctness of your solution using the PIDs and PPIDs of the generated processes

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

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Explain the key areas in which service employees need training.

Answered: 1 week ago

Question

Understand the role of internal marketing and communications.

Answered: 1 week ago