shell Jobs

concept: only 1 foreground program can be running on a shell terminal, however several can run in the background. Here’s how.

  • [program] &
    launches the program directly into the background
  • CTRL+Z
    suspends the program currently running in the foreground into stopped state into the background
  • jobs -l
    lists current background programs
  • fg %[n]
    puts into foreground the job number [n]
  • bg %[n]
    makes program [n] run into the background. The program should already be backgrounded, however after CTRL+Z it is in stopped state, thus this command brings it back to running state
    an alternative solution is command
    kill -cont pidnr
  • there are stopped jobs
    error message while attempting to log out notifies you that there are some jobs still hanging around. Use jobs and fg %[n] to terminate them correctly without data loss
  • kill %[n]
    terminates [n] job
  • logout logout
    logs out terminating all backgrounded jobs
    NOTE: with this command only backgrounded jobs in stopped state will be terminated, not those in running state.

screen

screen is a tty detachable emulator. you can use it with command
screen [program] args
to list all program executed with screen command
screen -list
to reattach a program executed with screen command (pid is taken from previous command)
screen -r [pid][tty][host]

shortcuts are
CTRL+ad  to detach a program using screen
CTRL+DD to detach a program using screen and logout (notice the capital D)

Related posts:

  1. Basic commands for GNU/Linux – BSD (part 2)
  2. How to write an interactive shell script
  3. Basic commands for GNU/Linux – BSD (part 1)
  4. change keyboard layout in shell
  5. Cron daemon – recurrent tasks
  6. Basic commands for working with VI (and VIM)
  7. VMware Workstation 6.5.3 on Ubuntu Karmic 9.10
| Print This Post Print This Post | Email This Post Email This Post
RSS 2.0 | Trackback | Comment

Leave a Reply

XHTML: You can use these tags: b, cite, code, em, i, q cite="", strike, strong.