A job is any task that the computer performs for you, such as printing a file, listing file names on the screen, or compiling a program. You can run jobs in the foreground or background, or you can suspend a job and resume it later. From within an Interix shell, you can even control Windows jobs.
When you run a job, it is assigned two numbers: a job control number and a process identification (PID) number.
The job control number identifies jobs that you call from your terminal. The first job is assigned the number [1], the second [2], the third [3], and so on.
Interix shells support standard methods for job control. For example, assume that you "ping" your computer with the following:
ping 127.0.0.1
You can stop or suspend the job with CTRL+Z. You can see all jobs and their associated job control number by typing:
jobs
The output of jobs resembles:
[1] + Stopped ping 127.0.0.1
In this example, only one job is running. The plus sign (+) points to the current job. If you have multiple jobs running, only one will have a plus sign. The word Stopped indicates the job status, which, in this case, is stopped or suspended. A job that is running in the background will be listed as Running.
You can refer to a particular job by typing a percent symbol (%) followed by the job number. For example, to restart the ping in the foreground, type:
fg %1
Or, you can restart it in the background with bg %1. If a job normally sends output to the screen, it will continue to do so, even while running in the background. While it was suspended, you could have terminated the ping job with kill %1. For more information on job control, see fg(1), bg(1), kill(1), and jobs(1).
As was previously mentioned, each job is assigned a PID number in addition to a job control number. The Interix subsystem and Windows keep track of jobs with PID numbers; a unique PID is assigned to each job for each user.
In the Interix subsystem, the ps(1) (process status) command lists PIDs. In Windows, you can view PIDs in the Task Manager. Because the Interix subsystem has its own space for keeping track of PIDs, the ps command in an Interix shell lists PID numbers that are different from the PID numbers in Windows Task Manager.
From within an Interix shell, the job control commands fg, bg, and kill work with either Interix or Windows PIDs. For example, assume that you suspend a ping, start ps, and then see that the ping has a PID of 2049. You can kill the ping process with kill -9 2049.
You can also kill a Windows process. For example, assume that Task Manager lists a Notepad process as 472. From within an Interix shell, you could terminate this Notepad process with kill 472.
There are several differences between job control numbers and PID numbers. Each job is not assigned a unique job number on a computer. If two users are running programs on the same computer, their jobs can be assigned the same numbers, that is, [1], [2], [3], and so on. For example, User1 can have a ping(1) command that is assigned the number [1], while User2 can have a telnet(1) session that is assigned the same number [1]. Jobs on one computer are differentiated from one another by their PIDs. Every job started by every user is issued a unique PID. Also, only jobs that are stopped or put in the background are given job control numbers; all jobs, however, are assigned PIDs.