title | author | date | lang |
---|---|---|---|
Job management |
CSC Training |
2020-04 |
en |
UNIX/Linux are multi-tasking operating systems. Consequently, the users need to know something about managing their jobs (=running applications). This session deals with ...
- displaying jobs on your system
- fore- and background jobs in shell
- suspending and terminating of jobs
- Linux/UNIX are multi-tasking systems
- One can display the currently running jobs using the
top
command$ top
- press
P
to order jobs by their processor load - press
M
to order jobs by their memory consumption - press
u
to prompt for displaying jobs of certain user (entercscuser
) - press
q
to exit
- press
- By default commands (jobs) in the shell are run in foreground, e.g.,
$ emacs newfile
- Now, try to enter something in your shell
- It does not respond. Why?
- as long as you do not quit
emacs
(the currently running program), it blocks the shell - we say: the job (
emacs
in this case) is running in the foreground of the shell
- Terminating (=killing) a running foreground job: in shell press ctrl + C
- That is usually not recommended, except for non responding jobs
- Launch again into foreground
- Type something into
emacs
- Type something into
- Suspending a job: in shell press ctrl + z
- Shell reports on stopped job
- Type a command into the shell:
$ ls -ltr
- Try to type something into emacs. What happens?
- The process of
emacs
is suspended, hence does not accept any input- In fact, the input buffer keeps the typed stuff and will fill it into
emacs
, once it is active again
- In fact, the input buffer keeps the typed stuff and will fill it into
- The process of
- Try to type something into emacs. What happens?
- Sending the suspended job to background:
$ bg
- type a command into the shell:
$ ls -ltr
- type something into emacs
- It works now for both! Because
emacs
is running in background and your shell accepts commands
- Fetching back to foreground:
$ fg
- Shell is blocked again
emacs
accepts input- quit
emacs
either by menu or ctrl+x, ctrl+c
- Can I directly launch into background ?
- Yes. Type command followed by
&
$ emacs newfile &
- Yes. Type command followed by
- Lets launch two jobs into background
$ xterm -T "first" & $ xterm -T "second" &
- if program
xterm
is not installed, install it
- if program
- To list all jobs of the shell:
should report something like (numbers in brackets might differ)
$ jobs
[1] - Running xterm -T "first" & [2] + Running xterm -T "second" &
- the
+
after job[2]
means that job[2]
listens to commands, likefg
- the
- Bringing job
[1]
to foreground needs a way to address the job:$ fg %1 -> xterm -T "first"
- address a certain job with
%
followed by its number - to send it back ctrl + z, followed by
$ bg
- address a certain job with
- To kill (= terminate) a certain job
$ kill -9 %1 $ jobs -> [1]- Killed xterm -T "first" [2]+ Running xterm -T "second" &
- Playing terminator (killing all jobs of a kind):
$ for i in {1..5}; do xterm & done $ pkill xterm
- this first launches 5 xterms and then kills all xterm processes under your user-id