![]() |
![]() |
The first project will be for you to write
your own shell to replace the standard Operating System
shell.
The Shell or Command Line Interpreter (CLI) that is your environment when you logon to a UNIX system is usually the TENEX/TOPS/Thomas C Shell (tcsh), a completely compatible version of the Berkeley UNIX C shell, csh. It is a command language interpreter usable both as an interactive login shell and a shell script command processor. It includes a command-line editor, programmable word completion, spelling correction, a history mechanism, job control, i/o redirection, and a C-like syntax (see http://www.tcsh.org/Home for the full description of the ongoing development of tcsh). Read Glass (UNIX for Programmers and Users) Chapters 3 and 6 and the tutorial on Shell Programming: shells.html with particular reference to the sections on i/o redirection and process control Write a small program, sleepy, that gets a loop count from the command line:
where n is the number of seconds for which the program should run. Implement this timing by putting a loop n times of sleep(1) - this will put the program to sleep for one second n times before exitting.
In each loop print out the process ID and the loop count so that that particular process can be identified. The process ID can be obtained from the getpid function:
The process ID is returned as a type pid_t which is actually an integer so it can be treated as such in a printf format statement (use an int cast to avoid a compile warning from gcc). Use this program to investigate the process control of the shell provided on your UNIX system. In particular learn how to:
Code should be in 'straight' C using the compiler of your choice (cc or gcc). Always use nice to
execute your test programs at lower priority to ensure they do not inconvenience
other users if they go 'haywire'. e.g.: The descriptions of the system functions above are drawn from
sources that include |
![]() | ![]() | ![]() |
For use only by students and instructors using the supplementary material available with the text book: "Operating Systems - Internals and Design Principles", William Stallings, Prentice Hall, 5th Edition, 2004. Not to be printed out or copied by any other persons or used for any other purpose without written permission of the author(s).
©