Processes and jobs

What are the differencess

Posted by Eirik on 27 Feb, 2024

In Linux systems, “process” and “job” are two distinct concepts representing different units of execution. Here’s the difference between them along with some common examples:

  1. Process:

    • A process is an instance of a program running in the operating system.
    • Each process has its own memory space, code, data, open files, resources, and state.
    • Processes are independent of each other and cannot directly access the memory space of other processes.
    • A process can have multiple threads, which are units of parallel execution within the process.
    • For example, when you run a program on the system, the system creates a process for that program.
  2. Job:

    • A job typically refers to a collection of related commands or tasks that can be managed and executed as a single unit.
    • A job can consist of one or more processes.
    • Jobs are often associated with terminal sessions.
    • Jobs can be executed in the foreground or background.
    • For example, in a command-line interface, you can use job control to start, pause, terminate, and manage jobs.

Common examples:

  • When you launch a program in the terminal, the operating system creates a process for that program. For instance, running a text editor or compiler.
  • When you initiate a set of tasks in the command line, they can be managed as a job. This might include a script containing multiple commands or a complex data processing task.
  • In the command line, you can use job control to manage background jobs, such as putting a task in the background to run without occupying control of the current terminal.

在Linux系統中,process(進程)job(作業)是兩個不同的概念,它們代表不同的執行單元。

下面是它們的區別以及一些常見的例子:

進程(Process):

進程是作業系統中正在執行的程式的實例。 每個進程都有自己的記憶體空間、程式碼、資料、打開的檔案、資源和狀態。 進程之間是相互獨立的,它們無法直接訪問其他進程的記憶體空間。 一個進程可以擁有多個執行緒,執行緒是進程內部並行執行的單位。 例如,當您在系統上執行一個程式時,系統會為該程式創建一個進程。

作業(Job):

作業通常是一組相關的命令或任務的集合,可以作為一個單獨的單元來管理和執行。 作業可以包含一個或多個進程。 作業通常與終端會話(Terminal Session)相關聯。 作業可以在前台或後台執行。 例如,在命令列中,您可以使用作業控制來啟動、暫停、終止和管理作業。

常見例子:

當您在終端中啟動一個程式時,作業系統會為該程式創建一個進程。例如,運行一個文字編輯器或編譯器。 當您在命令列中啟動一個任務集合時,這些任務可以作為一個作業來管理。例如,一個包含了多個命令的腳本或一個複雜的資料處理任務。 在命令列中,您可以使用作業控制來管理後台作業,例如將一個任務放到後台執行,讓它不佔用當前終端的控制權。


Each process has its memory space

One process cannot corrupt the memory space of another process

Processes are independent

Chrome is famous for running every tab in different processes.

A thread is the unit of execution within a process

A process has at least one thread called main thread

Each thread has its own stack (stack, registers, program counters)

Threads within a proceess share a memory address spcae.

Pertains shared memory space, threads needs to communicate

The misbehaving thread could bring down the entire process.