Read ps(1), top(1) and kill(1). Experiment by creating applications in windows using the desktop controls, using ps to find the PID and kill -9 PID to kill these windows.
Write a 'C' program sleepy.c which uses the sleep(3) function to provide a runtime of 600 seconds. Write a shell script which uses ps, awk, grep and kill to obtain the PID for sleepy and kill it. Hints: use a pipeline started by the output of a ps command, then using grep to obtain the required row, grep -v grep to remove the unwanted grep command from the rows obtained, and awk to select the required column. When this works, put the PID output into a shell variable by enclosing the pipeline using grave (``) quotes. Use echo $variable to confirm you have got this PID correct before extending you shell script with the kill command to kill the sleepy process. How would you change this script to kill the parent shell process for your sleepy process ?
Read fork(2), wait(2), execve(2) and exec(3).
Write an interactive program: launcher.c which operates a main loop prompting the user for command lines, including program names and arguments which are to be spawned as child processes by launcher. launcher should wait for each child process to finish before reprompting the user. If the user enters the builtin command: "exit" , your launcher program should detect this, and instead of launching an external program it should implement this builtin by terminating.
Hints: to read a string from the keyboard including spaces you will find fgets() is better suited than scanf(). You will need to put the addresses of the command and argument words in your input buffer string into an array of pointers to char. You can ensure each word (command name or argument) is null ('\0') terminated by replacing spaces and the final '\n' in your string input buffer with the required '\0' string terminator character. You can use whichever member of the exec family of functions you find easiest, however your program must be able to handle commands with a variable number of arguments, so you are likely to have to provide the required list of string pointer arguments to the exec function selected as an array of these, with a NULL pointer as the array element following your last '\0' terminated string address.