



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
An introduction to unix shells and a set of routines for manipulating jobs stored in a list as part of a bigger assignment on process control and signaling. It includes function definitions, global variables, and test cases for the functions. The assignment aims to expand the understanding of topics such as job control, pointers, and structures in c.
Typology: Assignments
1 / 5
This page cannot be seen from the preview
Don't miss anything!




This is the first part of a bigger assignment on process control and signaling. To expand your understanding on these topics, you will write a simple Unix shell program that supports job control.
This first assignment asks you to write a few helper routines for job manipulation. In doing so, you will also learn how to manipulate pointers and structures in C. This assignment must be completed individually.
A shell is an interactive command-line interpreter that runs programs on behalf of the user. A shell repeat- edly prints a prompt, waits for a command line on stdin, and then carries out some action, as directed by the contents of the command line.
The command line is a sequence of ASCII text words delimited by whitespace. The first word in the command line is either the name of a built-in command or the pathname of an executable file. The remaining words are command-line arguments. If the first word is a built-in command, the shell immediately executes the command in the current process. Otherwise, the word is assumed to be the pathname of an executable program. In this case, the shell forks a child process, then loads and runs the program in the context of the child. The child processes created as a result of interpreting a single command line are known collectively as a job.
If the command line ends with an ampersand ”&”, then the job runs in the background, which means that the shell does not wait for the job to terminate before printing the prompt and awaiting the next command line. Otherwise, the job runs in the foreground, which means that the shell waits for the job to terminate before awaiting the next command line. Thus, at any point in time, at most one job can be running in the foreground. However, an arbitrary number of jobs can run in the background.
For example, typing the command line
tsh> jobs
causes the shell to execute the built-in jobs command. Typing the command line
tsh> /bin/ls -l -d
runs the ls program in the foreground. By convention, the shell ensures that when the program begins executing its main routine
int main(int argc, char (^) *argv[])
the argc and argv arguments have the following values:
Alternatively, typing the command line
tsh> /bin/ls -l -d &
runs the ls program in the background.
Unix shells support the notion of job control, which allows users to move jobs back and forth between back- ground and foreground, and to change the process state (running, stopped, or terminated) of the processes in a job. Unix shells provide various built-in commands that support job control. For example:
Each job can be identified by either a process ID (PID) or a job ID (JID), which is a positive integer assigned by tsh. JIDs should be denoted on the command line by the prefix ’%’. For example, “%5” denotes JID 5, and “ 5 ” denotes PID 5.
In this assignment you will write a set of routines for manipulating jobs stored in a list. Start with the following definitions:
Thoroughly test each function by creating sample calls in the main function. Here is an example:
int main()
initjobs(jobs); listjobs(jobs); addjob(jobs, 111, FG, "ls -l"); listjobs(jobs); /* etc. (^) */
Hint: To find out the name of a header containing the declaration of a particular function, type in
man function name
at the shell prompt. For instance, typing in
man strcpy
will list information about the strcpy function.
Your score will be computed out of a maximum of 50 points based on the following distribution:
40 Correctness.
10 Style points. We expect you to have good comments and to check for errors (eg., deleting from an empty list, or checking the validity of an argument (jid ¿ 0, for instance), or checking for NULL pointers, etc.). Do not allow me to break your code by trying something like
addjob(jobs, 100, FG, 0); listjobs(jobs);
Hand in a printed copy of your source code (tsh.c) and a short README file explaining any bugs and deviations from the assignment specifications. Make sure you have included your name and your Unix login name in the README file. Leave your source code in your Unix account. I will test your code on felix. Good luck!