Section A, B, C, D, E
Operating System Spring 2013 Assignment # 02
Submission Deadline Thursday, 14th March 2013 at Sharp 11:55pm
Question # 01 (10 Marks)
In this programming exercise, you are asked to use the fork() programming construct to create some number of processes, specified on the command line - for example - the command ./FORK1.exe 6 should create 6 new simultaneously-executing processes as quickly as possible. Each process except the original should then print out its own process ID using getpid() which returns the current process ID when it is called. After printing out the process ID, each process should wait for two (2) seconds by calling sleep(2) and then exiting: exit(). The main - parent process should wait three (3) seconds before exiting. Use atoi() to convert the input from command line from ascii to integer.
Question # 02 Part (a) (shell alike) 10Marks
Write a shell-like program that illustrates how LINUX spawns processes. This simple program will provide its own prompt to the user, read the command from the input and execute the command. It is sufficient to handle just argument-less commands, such as ls and date.
Part (b) (passing and parsing arguments) 10 Marks
Make the mini-shell (from the previous part) a little more powerful by allowing arguments to the commands. For example, it should be able to execute commands such as more filename and ls –l ~/tmp etc. You must handle other commands as well.
Part (c) (Redirecting output using dup2) 15 Marks
Add to the MoreShell ability to execute command lines with commands connected by pipes. Use dup2 system call to redirect IO. For Example: ls -l | wc .
Question # 02 (15 Marks)
Write a program that uses fork() to create one child process named CHILD. Using pipe(), establish a pipe between parent and child. Using dup2(), attach file descriptors for stdin and stdout to the pipe. Parent takes data from the keyboard (stdin) and adds a suffix "-PARENT-PROCESSED" to the data....
Please join StudyMode to read the full document