



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Professor: Ligatti; Class: Operating Systems; Subject: Computer Programming; University: University of South Florida; Term: Fall 2006;
Typology: Assignments
1 / 5
This page cannot be seen from the preview
Don't miss anything!




We have provided a sample input file ( input.dat ), which you can use to test your program. We will be using a different input file for the evaluation of assignments. b) Read one line of the input file (you can use fgets() to read a complete line). c) Fork a child process. d) Inside the child process, identify the parent’s process id (C- function: getppid ) and the self process id (C-function: getpid ). Pass the command line that was read in step (b), the parent’s id, and the self id to a function called process1. e) In process1, perform the following: Convert the input line into the format that the execvp() function accepts: execvp(char *command, char *params[]), where command represents the command to be performed and params stores the parameters to this command. N.B.: We have provided a function called setup to help you perform this conversion. Print the parent and child pids on the console. Execute the command using execvp and display the results on the console. Exit from the child process. f) Perform steps (b), (c), and (d) until the end of file is reached. While a child process is executing, make the parent process wait until the child finishes. When the child exits, the parent should print a message indicating which child has just exited. g) Close the input file. h) Create another child process. i) Inside the child process, identify the parent and self pids, and pass them to a function called process2. j) In process2, perform the following: Setup a signal handler to exit the program (i.e., the child process) when a keyboard interrupt signal Ctrl-\ is pressed. Create a signal handling message: “\n\nSignal
gcc as1.c a.out usage: a.out filename a.out input.dat Parent pid = 21270, child pid = 21271 total 64 -rw------- 1 ligatti faculty 50688 Sep 7 15:44 Handout.doc -rwx------ 1 ligatti faculty 9028 Sep 8 10:41 a.out -rw------- 1 ligatti faculty 3871 Sep 7 21:12 as1.c -rw------- 1 ligatti faculty 48 Sep 7 19:30 input.dat Child with pid 21271 has just exited. Parent pid = 21270, child pid = 21272 /home/csee2/ligatti/4600/as Child with pid 21272 has just exited. Parent pid = 21270, child pid = 21273 "try it - It Should Work" Child with pid 21273 has just exited. Parent pid = 21270, child pid = 21274 UID PID PPID C STIME TTY TIME CMD ligatti 20870 20361 1 10:36:36 pts/14 0:01 -tcsh ligatti 21270 20870 0 10:42:14 pts/14 0:00 a.out input.dat Child with pid 21274 has just exited. Parent pid = 21270, child pid = 21275 *** ERROR: exec failed Child with pid 21275 has just exited. Parent pid = 21270, child pid = 21276 ^
Signal<> has been caught. Quit
SUBMISSION NOTES Type the following pledge as an initial comment in your C file: “I pledge my Honor that I have not cheated on this assignment.” Type your name after the pledge. Not including this pledge will lower your grade 50%. Upload as1.c onto Blackboard using the digital drop-box. You can make any number of submissions; we will evaluate the latest submission. It is your responsibility to ensure that your program compiles on the Unix machines. For every day your assignment is late, your grade reduces 10%.
The program must be commented appropriately.