CS 350 Fall 2008 Programming Assignment 3: Parent-Child Cooperation - Prof. Bojan Cukic, Assignments of Computer Science

A programming assignment for cs 350, a university course, where students are required to write a program using parent-child cooperation in unix. The program offers a menu for users to display the current date and time, the calendar for the current month, list files in the current directory, or quit the program. For each choice other than quit, the parent process creates a child process to execute the requested unix command using system(...). The child process terminates upon execution of the command, and the parent process waits for it to terminate before displaying the menu again. The document also includes instructions for submission and academic honesty.

Typology: Assignments

Pre 2010

Uploaded on 07/30/2009

koofers-user-x5r
koofers-user-x5r 🇺🇸

4.3

(3)

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 350, Fall 2008
PROGRAMMING ASSIGNMENT #3
Parent-Child Cooperation
(You may download this assignment statement from http://www.csee.wvu.edu/~cukic)
Submission Deadline: 11:59 PM, Sunday, Nov 16th, 2008
Write a program, based on parent-child cooperation, where the parent process offers the program user a menu whose options
are to:
1. Display the current date and time,
2. Display the calendar for the current month,
3. List files in the current directory,
4. Quit the program.
For any choice other than quit, the parent should create a child process that invokes a call to system(…) to execute the
requested UNIX command. UNIX command 'date' can be used for choice #1, 'cal' for #2, and 'ls -l' for #3. Make sure that
upon the execution of a single UNIX command, the child process terminates (dies). Before displaying the menu again, the
parent should wait for the child process to terminate executing the previous command. When the user chooses to quit, the
parent process terminates.
When writing the program, make sure that you display the identification number of the process that displays the information.
So, for example, a suggested output of a run of your program should look similar to the following:
Parent process ID: 2765, Parent's parent ID: 904
Choose the function to be performed by the child:
(1) Display current date and time
(2) Display the calendar of the current month
(3) List the files in the current directory
(4) Exit from the program
Enter your choice: 1
Child process ID 2766; Parent ID 2765
Fri Nov 26 17:36:25 EST 1999
Current process PID 2765
Choose the function to be performed by the child:
(1) Display current date and time
(2) Display the calendar of the current month
(3) List the files in the current directory
(4) Exit from the program
Enter your choice: 3
Child process ID 2774; Parent ID 2765
total 18
-rwxr-xr-x 1 cukic 5093 6740 Nov 26 16:58 a.out
-rw-r--r-- 1 cukic 5093 1150 Nov 26 16:59 a3.c
Current process PID 2765
Choose the function to be performed by the child:
(1) Display current date and time
pf2

Partial preview of the text

Download CS 350 Fall 2008 Programming Assignment 3: Parent-Child Cooperation - Prof. Bojan Cukic and more Assignments Computer Science in PDF only on Docsity!

CS 350, Fall 2008

PROGRAMMING ASSIGNMENT

Parent-Child Cooperation

(You may download this assignment statement from http://www.csee.wvu.edu/~cukic)

Submission Deadline: 11:59 PM, Sunday, Nov 16th, 2008

Write a program, based on parent-child cooperation, where the parent process offers the program user a menu whose options are to:

  1. Display the current date and time,
  2. Display the calendar for the current month,
  3. List files in the current directory,
  4. Quit the program.

For any choice other than quit, the parent should create a child process that invokes a call to system(…) to execute the

requested UNIX command. UNIX command 'date' can be used for choice #1, 'cal' for #2, and 'ls -l' for #3. Make sure that

upon the execution of a single UNIX command, the child process terminates (dies). Before displaying the menu again, the

parent should wait for the child process to terminate executing the previous command. When the user chooses to quit, the

parent process terminates.

When writing the program, make sure that you display the identification number of the process that displays the information. So, for example, a suggested output of a run of your program should look similar to the following:

Parent process ID: 2765, Parent's parent ID: 904 Choose the function to be performed by the child: (1) Display current date and time (2) Display the calendar of the current month (3) List the files in the current directory (4) Exit from the program

Enter your choice: 1 Child process ID 2766; Parent ID 2765 Fri Nov 26 17:36:25 EST 1999

Current process PID 2765 Choose the function to be performed by the child: (1) Display current date and time (2) Display the calendar of the current month (3) List the files in the current directory (4) Exit from the program

Enter your choice: 3 Child process ID 2774; Parent ID 2765 total 18 -rwxr-xr-x 1 cukic 5093 6740 Nov 26 16:58 a.out -rw-r--r-- 1 cukic 5093 1150 Nov 26 16:59 a3.c

Current process PID 2765 Choose the function to be performed by the child: (1) Display current date and time

(2) Display the calendar of the current month (3) List the files in the current directory (4) Exit from the program

Enter your choice: 2 Child process ID 2797; Parent ID 2765 December 1999 S M Tu W Th F S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Current process PID 2765 Choose the function to be performed by the child: (1) Display current date and time (2) Display the calendar of the current month (3) List the files in the current directory (4) Exit from the program

Enter your choice: 4

Current process PID 2765 Program terminated

Of course, every time you run your program, the process ID numbers will be different, reflecting the run-time assignment of

process PIDs. Some of the C function calls you will need to use in this program are fork( ), getpid( ),

getppid( ),sprintf( ), system( ), exit( ), wait( ), etc. The use of these functions is very

well described in one of the recommended textbooks ("UNIX Systems Programming, see the reference in the sylabus"). For

the description of exit( ), wait( ) system calls, take a look at the descriptions in sections 2.11 and 3.4 of the same

textbook. The following header files should most likely be included in your programs:

#include <stdio.h> #include <sys/types.h> #include <unistd.h>

Submission

In order to be graded, you must submit the following:

  1. Submit all the program files following the procedure described in my Web page: (http://www.csee.wvu.edu/~cukic/CS350 follow the link “How to submit programming assignments”). Programs submitted through e-mail will be rejected! It is your responsibility to submit programs successfully. 2. Submit program documentation in class on Tuesday, Nov. 18th. If your program does not work properly or if it does not compile, state this clearly in the documentation. 3. Submit the listing of your code. Please make sure that your program is well documented, use comments to explain what certain part of your program does. The header of the file MUST contain your name, student ID, and your account name. I will not grade your assignment unless I have program documentation and listing.
  2. To receive credit, your program must be submitted by Friday November 21st. No programs or their accompanying documentation will be accepted after the stated deadline (final grades available on Dec. 6th).

Academic Honesty:

Each student is expected to develop his/her assignment alone. Do not share programs, or program parts, with your colleagues. Violators of this policy will be held responsible for academic dishonesty, and will bear consequences in accordance to the rules and regulations of West Virginia University.