CTRL+C Interrupting a Process

Many (but not all) command line programs can be interrupted by using CTRL+C.

  1. $ xlogo # 运行 xlogo 后,shell 处于等待 xlogo 结束的状态,此时 Press CTRL+C
  2. ^C
  3. $

& Putting a Process in the Background Immediately

  1. $ xlogo &
  2. [1] 8108
  3. $

This message is part of a shell feature called job control. With this message, the shell is telling us that we have started job number 1 ([1]) and that it has PID 28236.

  1. $ ps
  2. PID TTY TIME CMD
  3. 7288 pts/1 00:00:00 bash
  4. 8180 pts/1 00:00:00 xlogo
  5. 8120 pts/1 00:00:00 ps

jobs List Jobs

  1. $ jobs
  2. [1]+ Running xlogo &

fg Returning a Process to the Foreground

**fg %jobspec**

  • If we have only one background job, the jobspec(job numer) is optional.

    1. $ fg %1
    2. xlogo

    CTRL+Z Stopping (Pausing) a Process

    **CTRL+Z** does 2 things:

  • Stop a process without ternimating it;

  • Place the process in the background.
    1. $ xlogo
    2. ^Z
    3. [1]+ Stopped xlogo &
    After stopping xlogo program, the xlogo window does not respond to window resizing.

    bg Putting a Process in the Background Manually

    We may use bg to move a process from the foreground to the background If we launch a graphical program from the command line but forget to place it in the background by appending the trailing $.
  1. First, stop the program by pressing CTRL+Z;
  2. Second, run bg %jobspec
    • As with the fg, If we have only one background job, the jobspec(job numer) is optional.
      1. $ xlogo # forget the trailing $
      2. ^Z
      3. [1]+ Stopped xlogo &
      4. $ bg %1
      5. $