The purpose of this recitation is to write two short C programs showing the parent-child process...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
The purpose of this recitation is to write two short C programs showing the parent-child process relationship in Linux using the fork () system call. Specifically, we will look at how a zombie and orphan process are created as well as handled by the operating system. 1. Zombie Process Recall that when a child terminates, but its parent is not currently waiting, the terminated child process becomes a zombie process. Use the following algorithm and specific instructions to develop a short, simple C program called rec06A. c to create a zombie process. a. Add the include directives for the stdlib.h and unistd.h libraries. b. Declare a variable called pid with the data type pid_t and invoke the fork() system call, assigning the result to pid. c. Write an if – else if - else branching statement to handle the child process, parent process, and error case, respectively. i. In the child process, exit immediately. ii. In the parent process, sleep for 5 seconds, then issue the system () system call with "ps -e -o pid,ppid, stat,user,cmd | grep $USER". This prints out the current PID, parent PID, status, user ID, and command process information. iii. In the error case, call the perror () system call with "fork error". Now, compile and run your program. After 5 seconds, you should see the result of the ps command. Specifically, look for the process with the Z+ status. This is an indication that it is a zombie process. This process should also be the child process of your parent . /a.out executable that contains the <defunct> indicator. Now, on the command line, enter the ps-u $USER command to see your existing processes. You should notice that this zombie process no longer exists as it has been reaped by the init/systemd process. You will turn in this rec06A. c file to Canvas. 2. Orphan Process Recall that a child process whose parent has terminated is referred to as an orphan process. This means that the child is still executing, but its parent has terminated and that some process is then needed to handle the child's exit status. Use the following algorithm and specific instructions to develop a short, simple C program called rec06B. c to create an orphan process. a. Add the include directives for the stdio.h, stdlib.h and unistd.h libraries. 1 b. Declare a pointer to a char called name. Declare a variable called pid with the data type pid_t and invoke the fork () system call, assigning the result to pid. C. d. Write an if-else if-else branching statement to handle the child process, parent process, and error case, respectively. i. In the child process, print "child: %d started\n" using the getpid () system call for the %d. Then, print "child: parent = %d\n" using the getppid() system call for the %d. Now, print another child status (use "child: ...") to indicate the child is about to go to sleep. Then, sleep for 20 seconds. Finally, print a child status to indicate that the child just woke up. ii. In the parent process, print "parent: %d started\n" using the getpid() system call for the %d. Then print "parent: parent = %d\n" using the getppid () system call for the %d. iii. In the error case, call the perror () system call with "fork error". e. Outside of the if-else if-else branching statement, use the ternary operator (condition) ? (if_true) : (if_false) to assign "child" to the name character pointer if pid is 0 and "parent" otherwise. Then, print "%s: terminating...\n" using the name character pointer for the %s. Now, compile and run your program. After your program initially runs, but before the child process has terminated, enter the ps -ef | grep $USER command to see your existing processes. You should notice your child process is still running, but has 1 for its parent process - this means that the init/systemd process has taken over as the parent (since our parent terminated) and will handle the child once it has terminated. You will turn in this rec06B . c file to Canvas. REQUIREMENTS: • No comments are required for this recitation assignment, except for your name at the top of each program. Your script will be graded based largely on whether it works correctly on the CSE machines (e.g., cse01, cse02, ..., cse06), so you should make sure that your script runs on a CSE machine. • Although this assignment is to be submitted individually (i.e., each student will submit his/her own source code), you may receive assistance from your TA and even other classmates. Please remember that you are ultimately responsible for learning and comprehending this material as the recitation assignments are given in preparation for the minor assignments, which must be completed individually. SUBMISSION: • You will electronically submit your programs, rec06A.c and rec06B.c, to the Recitation 6 dropbox in Canvas by the due date and time. No late recitation assignments will be accepted. The purpose of this recitation is to write two short C programs showing the parent-child process relationship in Linux using the fork () system call. Specifically, we will look at how a zombie and orphan process are created as well as handled by the operating system. 1. Zombie Process Recall that when a child terminates, but its parent is not currently waiting, the terminated child process becomes a zombie process. Use the following algorithm and specific instructions to develop a short, simple C program called rec06A. c to create a zombie process. a. Add the include directives for the stdlib.h and unistd.h libraries. b. Declare a variable called pid with the data type pid_t and invoke the fork() system call, assigning the result to pid. c. Write an if – else if - else branching statement to handle the child process, parent process, and error case, respectively. i. In the child process, exit immediately. ii. In the parent process, sleep for 5 seconds, then issue the system () system call with "ps -e -o pid,ppid, stat,user,cmd | grep $USER". This prints out the current PID, parent PID, status, user ID, and command process information. iii. In the error case, call the perror () system call with "fork error". Now, compile and run your program. After 5 seconds, you should see the result of the ps command. Specifically, look for the process with the Z+ status. This is an indication that it is a zombie process. This process should also be the child process of your parent . /a.out executable that contains the <defunct> indicator. Now, on the command line, enter the ps-u $USER command to see your existing processes. You should notice that this zombie process no longer exists as it has been reaped by the init/systemd process. You will turn in this rec06A. c file to Canvas. 2. Orphan Process Recall that a child process whose parent has terminated is referred to as an orphan process. This means that the child is still executing, but its parent has terminated and that some process is then needed to handle the child's exit status. Use the following algorithm and specific instructions to develop a short, simple C program called rec06B. c to create an orphan process. a. Add the include directives for the stdio.h, stdlib.h and unistd.h libraries. 1 b. Declare a pointer to a char called name. Declare a variable called pid with the data type pid_t and invoke the fork () system call, assigning the result to pid. C. d. Write an if-else if-else branching statement to handle the child process, parent process, and error case, respectively. i. In the child process, print "child: %d started\n" using the getpid () system call for the %d. Then, print "child: parent = %d\n" using the getppid() system call for the %d. Now, print another child status (use "child: ...") to indicate the child is about to go to sleep. Then, sleep for 20 seconds. Finally, print a child status to indicate that the child just woke up. ii. In the parent process, print "parent: %d started\n" using the getpid() system call for the %d. Then print "parent: parent = %d\n" using the getppid () system call for the %d. iii. In the error case, call the perror () system call with "fork error". e. Outside of the if-else if-else branching statement, use the ternary operator (condition) ? (if_true) : (if_false) to assign "child" to the name character pointer if pid is 0 and "parent" otherwise. Then, print "%s: terminating...\n" using the name character pointer for the %s. Now, compile and run your program. After your program initially runs, but before the child process has terminated, enter the ps -ef | grep $USER command to see your existing processes. You should notice your child process is still running, but has 1 for its parent process - this means that the init/systemd process has taken over as the parent (since our parent terminated) and will handle the child once it has terminated. You will turn in this rec06B . c file to Canvas. REQUIREMENTS: • No comments are required for this recitation assignment, except for your name at the top of each program. Your script will be graded based largely on whether it works correctly on the CSE machines (e.g., cse01, cse02, ..., cse06), so you should make sure that your script runs on a CSE machine. • Although this assignment is to be submitted individually (i.e., each student will submit his/her own source code), you may receive assistance from your TA and even other classmates. Please remember that you are ultimately responsible for learning and comprehending this material as the recitation assignments are given in preparation for the minor assignments, which must be completed individually. SUBMISSION: • You will electronically submit your programs, rec06A.c and rec06B.c, to the Recitation 6 dropbox in Canvas by the due date and time. No late recitation assignments will be accepted.
Expert Answer:
Answer rating: 100% (QA)
The images you provided contain instructions for programming assignments to create a zombie process and an orphan process in C language The instructio... View the full answer
Related Book For
Modern Systems Analysis And Design
ISBN: 9780134204925
8th Edition
Authors: Joseph Valacich, Joey George
Posted Date:
Students also viewed these programming questions
-
Blossom Products purchased a machine for $67100 on July 1, 2025. The company intends to depreciate it over 8 years using the double-declining balance method. The salvage value is $5000. Depreciation...
-
Write a literature review for your study. See below for an example of a literature review. Your literature review should provide both analysis and synthesis of previous studies as related to the...
-
Write a project management plan. we have a template and project description. we need to edit the template(table of contents) with our own ideas. CPSC 8820-01 Project Management Plan Your Unique...
-
Ava bought a house on 1 July 2000 for 62,000. She occupied the entire property as her PPR until 1 August 2007 when she began using one-quarter of the house for business purposes. This continued until...
-
The current in a resistor decreases by 3.00 A when the voltage applied across the resistor decreases from 12.0 V to 6.00 V. Find the resistance of the resistor.
-
A pulley is hung from the ceiling by a rope. A block of mass M is suspended by another rope that passes over the pulley and is attached to the wall. The rope fastened to the wall makes a right angle...
-
A food processing company is designing the packaging for a new product line of potato chips. The expected shelf life of the potato chips is 10 months. The bag has to hold \(200 \mathrm{~g}\) of...
-
Sales mix, new and upgrade customers. Zapo 1-2-3 is a top-selling electronic spreadsheet product. Zapo is about to release version 5.0. It divides its customers into two groups: new customers and...
-
A driver needs new tires for her car and is trying to decide if she should purchase "low rolling resistance" tires. The regular tires cost $300 (for all 4 tires) and will last 3 years. The "low...
-
In July 2006, Tata Motors, an Indian auto maker, and Fiat Auto, an Italian automaker, announced their intention to form a joint venture to produce passenger cars, engines, and transmissions in India....
-
You are the manager for a project with a budget of $250,000 and are employing three teams of three engineers, each for a total of 8 weeks. Each team has a budget of $80,000, and you have a...
-
What are the opportunities presented by climate change adaptation/emission mitigation policies for the supply-chain logistics sector? These could be specific laws, regulations, or other policy...
-
Denver Company had a fiscal year - end December 3 1 , 2 0 X 8 retained earnings account balance in its statement of financial position of $ 2 6 0 , 0 0 0 . During 2 0 X 8 , Denver Company had net...
-
6. What is the mass of 98 cm of water?
-
The company "Chanos Ltd " produces puzzles for adults within the framework of a standardized mass production. The production process uses 2 basic raw materials: cardboard and high quality ink. For...
-
A partial common-size income statement for Jag Company for three years is shown below. Net sales Item 2019 2018 2017 100.0 100.0 100.0 60.5 63.0 62.5 21.0 19.0 20.5 Cost of goods sold Other expenses...
-
Total number of 4 digit number do not having the digit 3 or 6.
-
Using the information presented in Problem 13.4B, prepare a partial statement of cash flows for the current year, showing the computation of net cash flows from operating activities using the...
-
What is information systems analysis and design?
-
Contrast the following terms: a. Dialogue, interface. b. Command language interaction, form interaction, menu interaction, natural language interaction, object- based interaction. c. Drop-down menu,...
-
Which installation strategy would you recommend for PVFs Purchasing Fulfillment System? Which would you recommend for Hoosier Burgers inventory control system? If you recommended different...
-
R-12 refrigerant belongs to which group of refrigerants? (a) halo-carbon (b) azeotropes (c) inorganic (d) hydro-carbons
-
Frosting of evaporator tubes results in (a) increased heat transfer rate (b) decreased heat transfer rate (c) increased compressor pressure (d) decreased compressor pressure
-
The bank of tube at the back of a domestic refrigerator of vapour compression type is (a) evaporator (b) condenser (c) capillary (d) electric wire
Study smarter with the SolutionInn App