A program is a file containing statements or commands in the form of source code or machine code. A process, in Unix terminology, is the execution of a program. By this we mean the running of a program, not a blindfold, a cigarette, and firing squad. A program is an object. A process is an action utilizing that object. A grocery list is like a program. A trip to the grocery store to buy what is on the list is like a process.
Unix is a multitasking system, which means that many processes can be running at any given moment, i.e. there can be many active processes.
When you log in, the system creates a new process to run your shell program. The same happens when other people log in. Hence, while everyone may be using the same shell program, they are all running different shell processes.
When you run a program (a command) from the shell, the shell creates a new process to run the program. Hence, you now have two processes running: the shell process and the command's process. The shell then normally waits for that child process to complete before printing the shell prompt again and accepting another command.
The process created by the shell to run your command is called a child process of the shell process. Naturally, the shell process is then called the parent process of the command process.
Each process is uniquely identified by an integer serial number called the process ID, or PID.
Unix systems also keep track of each process's status and resource usage, such as memory, CPU time, etc. Information about your currently running processes can be viewed using the ps (process status) command:
shell-prompt: ps PID TTY TIME CMD 7147 ttys000 0:00.14 -tcsh 7438 ttys000 0:01.13 ape notes.dbk unix.dbk 7736 ttys001 0:00.13 -tcsh
Run the ps command. What processes do you have running?
shell-prompt: ps
What if we want to see all the processes on the system, instead
of just our own? On most systems, we can add the
-a
(include other peoples' processes) and
-x
(include processes not started from a
terminal) flags.
shell-prompt: ps -ax
Another useful tool is the top command, which monitors all processes in a system and displays system statistics and the top (most active) processes every few seconds. Note that since top is a full-terminal command, it will not function properly unless the TERM environment variable is set correctly.
Run the top command. What processes are using the most CPU time? Type 'q' to quit top.
shell-prompt: top
Make sure you are using the latest version of this document.
Carefully read one section of this document and casually read other material (such as corresponding sections in a textbook, if one exists) if needed.
Try to answer the questions from that section. If you do not remember the answer, review the section to find it.
Write the answer in your own words. Do not copy and paste. Verbalizing answers in your own words helps your memory and understanding. Copying does not, and demonstrates a lack of interest in learning.
Check the answer key to make sure your answer is correct and complete.
DO NOT LOOK AT THE ANSWER KEY BEFORE ANSWERING QUESTIONS TO THE VERY BEST OF YOUR ABILITY. In doing so, you would only cheat yourself out of an opportunity to learn and prepare for the quizzes and exams.
Important notes:
Show all your work. This will improve your understanding and ensure full credit for the homework.
The practice problems are designed to make you think about the topic, starting from basic concepts and progressing through real problem solving.
Try to verify your own results. In the working world, no one will be checking your work. It will be entirely up to you to ensure that it is done right the first time.
Start as early as possible to get your mind chewing on the questions, and do a little at a time. Using this approach, many answers will come to you seemingly without effort, while you're showering, walking the dog, etc.
How does a process differ from a program?
If 10 people are logged in and using the same Unix shell, how many shell programs are there? How many shell processes?
What normally happens when you run a program from the shell?
How are processes identified in Unix?
How can we list all the processes currently running on the system?
How can we monitor which processes are using the most CPU and memory resources?