next up previous contents index
Next: Virtual Consoles: Being in Up: Multitasking Previous: The Basics

What Is Really Going On Here?

 

It is important to understand that job control is done by the shell. There is no program on the system called fg; rather, fg, bg, &, jobs, and kill are all shell-builtins (actually, sometimes kill is an independent program, but the bash shell used by Linux has it built in). This is a logical way to do it: since each user wants their own job control space, and each user already has their own shell, it is easiest to just have the shell keep track of the user's jobs. Therefore, each user's job numbers are meaningful only to that user: my job number [1] and your job number [1] are probably two totally different processes. In fact, if you are logged in more than once, each of your shells will have unique job control data, so you as a user might have two different jobs with the same number running in two different shells.

The way to tell for sure is to use the Process ID numbers (PID's). These are system-wide -- each process has its own unique PID number. Two different users can refer to a process by its PID and know that they are talking about the same process (assuming that they are logged into the same machine!)

Let's take a look at one more command to understand what PIDs are. The ps command will list all running processes, including your shell. Try it out. It also has a few options, the most important of which (to many people) are a, u, and x. The a option will list processes belonging to any user, not just your own. The x switch will list processes that don't have a terminal associated with them.gif Finally, the u switch will give additionally information about the process that is frequently useful.

To really get an idea of what your system is doing, put them all together: ps -aux. You can then see the process that uses the more memory by looking at the %MEM column, and the most CPU by looking at the %CPU column. (The TIME column lists the total amount of CPU time used.)CPU time

Another quick note about PIDs. kill, in addition to taking options of the form %job#, will take options of raw PIDs. So, put a yes > /dev/null in the background, run ps, and look for yes. Then type kill PID.gif

If you start to program in C on your Linux system, you will soon learn that the shell's job control is just an interactive version of the function calls fork and execl. This is too complex to go into here, but may be helpful to remember later on when you are programming and want to run multiple processes from a single program.


next up previous contents index
Next: Virtual Consoles: Being in Up: Multitasking Previous: The Basics

Converted on:
Mon Apr 1 08:59:56 EST 1996