66

What is the difference between a "job" and a "process"?

4 Answers 4

65

A process is any running program with its own address space.

A job is a concept used by the shell - any program you interactively start that doesn't detach (ie, not a daemon) is a job. If you're running an interactive program, you can press CtrlZ to suspend it. Then you can start it back in the foreground (using fg) or in the background (using bg).

While the program is suspended or running in the background, you can start another program - you would then have two jobs running. You can also start a program running in the background by appending an "&" like this: program &. That program would become a background job. To list all the jobs you are running, you can use jobs.

For more information on jobs, see this section of the bash man page.

5
  • In the above example, when we have 2 jobs running we also have 2 processes running, aren't we ? Could you elaborate the meaning of its own address space ? In which case a program does not have its own address space ?
    – Kenny
    Commented Nov 20, 2015 at 11:27
  • @Kenny yes, those tro jobs would also be processes. In fact, every job is a process. A job is related to your she'll session. Every process you start that doesn't detatch from your tty is a job. Commented Nov 20, 2015 at 18:01
  • @Kenny, as far as processes, when I say program, that's a very general thing - a set of ordered instructions for the CPU to carry out. This is also called a task or a thread of execution. A process may create another thread that shares its address space. Commented Nov 20, 2015 at 18:06
  • 4
    piped commands such as in ls | sort is a job, but each command runs as a child process of a different subshell process. This is an example of a job consisting of multiple processes. How can your definition of a job explain that a job can consist of multiple processes?
    – Tim
    Commented Feb 25, 2016 at 19:33
  • So am I correct in saying that a job consists of 1 or more processes, and a process is a component of a job?
    – jmrpink
    Commented Oct 5, 2021 at 21:00
43

UNIX has separate concepts "process", "process group", and "session".

Each shell you get at login becomes the leader of its own new session and process group, and sets the controlling process group of the terminal to itself.

The shell creates a process group within the current session for each "job" it launches, and places each process it starts into the appropriate process group. For example, ls | head is a pipeline of two processes, which the shell considers a single job, and will belong to a single, new process group.

A process is a (collection of) thread of execution and other context, such as address space and file descriptor table. A process may start other processes; these new processes will belong to the same process group as the parent unless other action is taken. Each process may also have a "controlling terminal", which starts off the same as its parent.

The shell has the concept of "foreground" jobs and "background" jobs. Foreground jobs are process groups with control of the terminal, and background jobs are process groups without control of the terminal.

Each terminal has a foreground process group. When bringing a job to the foreground, the shell sets it as the terminal's foreground process group; when putting a job to the background, the shell sets the terminal's foreground process group to another process group or itself.

Processes may read from and write to their controlling terminal if they are in the foreground process group. Otherwise they receive SIGTTIN and SIGTTOU signals on attempts to read from and write to the terminal respectively. By default these signals suspend the process, although most shells mask SIGTTOU so that a background job can write to the terminal uninterrupted.

3
  • 3
    This is a good, concise overview of shell and terminal process management. It could be improved by mentioning that a “job” is a “pipeline”, which can be more than one process connected together in a process group.
    – Chris Page
    Commented Dec 14, 2016 at 23:59
  • I don't understand this: "Each process may also have a "controlling terminal", which starts off the same as its parent." Does "controlling terminal" refer to the subshells that run the ls and head commands? If so, to what process does "its parent" refer to (which is the child and which is the parent) and what means "the same as" in that context?
    – The Quark
    Commented Sep 20, 2021 at 10:42
  • 1
    Controlling terminal refers to the tty device to which a process's stdin and/or stdout and/or stderr is connected. When a shell lauches a job, each process that is part of that job by default has its stdin, stdout and stderr pointing to the tty driver managing the session.
    – droptop
    Commented Mar 1, 2022 at 12:03
2

A job and a process are related but distinct concepts.

  • A process is an instance of a program that is currently running on the system. It has its own memory space, file descriptor, and a unique process ID (PID).

  • A job is a unit of work that the user wants to perform, it can be composed of one or more processes, and it can be managed by job control commands'. Jobs also have their own job ID (JID).

0
-3

Above definitions are very technical but maybe the op wanted a more day to day clarification. I think that a job is a scheduled process. When we deal with processes in general there is not necessarily the notion of schedule, but when we use the word "job" we always mean that it is scheduled, or repetitive like a loop, it's like a worker.

5
  • 1
    Please explain the votes down if you want to vote down. If this answer is not correct at least explain why you think it's not correct. Until now I still think my answer makes sense, it's the kind of explanation I was looking for.
    – eloone
    Commented Jul 20, 2017 at 17:52
  • I agree that the one who voted down should have explained why. But I think the reason for the downvote is that your definition of "job" simply isn't correct.
    – prograde
    Commented Apr 4, 2018 at 14:18
  • Care to explain why it's not correct? "Job" is not sth clearly defined like what a "process" is (with PID in the system). In my experience "job" was always a word used to define a certain kind of process that was often scheduled, and in the background, and that you can launch. That's why it's difficult to define because the usage defines it. It could also be a group of processes, but so is a "container" (LXC), but a "container" is not a "job". A launched process such as "nginx" is also not a "job". My comment still adds sth to the answer. Again, it answers what I was trying to understand.
    – eloone
    Commented Apr 4, 2018 at 20:57
  • I'm also still looking for a proper definition, so I'm sorry, I can't answer (yet). But what's not correct, is that it would have to be scheduled.
    – prograde
    Commented Apr 6, 2018 at 14:14
  • What is an example of a job that is not scheduled and recurring? we don't talk about a cron process for example, we talk about a cron job, and a cron is scheduled. Still not understanding the unexplained downvotes, they're not even giving people a chance to learn why this answer is wrong.
    – eloone
    Commented Jan 24, 2021 at 20:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .