Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

jobs

List the jobs of your shell, and move them between foreground (fg) and background (bg).

Niveau
RHCSA-examen
Groep
Processen en jobs
Root nodig
Nee
Pakket
bash (built-in)
Ook
bg, fg, disown

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

A job is a command (or pipeline) started from your current shell. COMMAND & starts it in the background; Ctrl+Z pauses the foreground job. jobs lists them with a number: %1, %2 …; + marks the current job, - the previous one.

bg continues a paused job in the background, fg brings a job to the foreground, and disown removes a job from the shell, so it keeps running when you log out. These are bash built-ins.

Zo schrijf je het

jobs [-lnprs] [JOBSPEC...]
bg [JOBSPEC...]
fg [JOBSPEC]
disown [-ar] [-h] [JOBSPEC...]

Belangrijkste delen

%N
Job number N.
%+ or %%
The current job.
%-
The previous job.
%STRING
The job whose command starts with STRING.
%?STRING
The job whose command contains STRING.

Opties 8

Meest gebruikt

jobs

-l
Also show the PIDs.
-p
Show only the PIDs (of the process group leaders).
-r
Only running jobs.
-s
Only stopped jobs.
-n
Only jobs that changed state since the last report.

disown

-h
Keep the job in the list, but do not send it SIGHUP at logout.
-a
All jobs.
-r
Only running jobs.

Voorbeelden 10

$ als gewone gebruiker# als root (of met sudo)

  1. 1Start a job in the background

    sleep 600 &
    [1] 4123

    Job number 1, PID 4123.

  2. 2List the jobs

    jobs -l
    [1]+  4123 Running                 sleep 600 &

    -l adds the PID.

  3. 3Pause and continue in the background

    tar -czf /tmp/home.tgz ~
    ^Z
    [1]+  Stopped                 tar -czf /tmp/home.tgz ~
    bg

    Ctrl+Z, then bg: the terminal is free again.

  4. 4Bring a job back

    fg %1

    Now Ctrl+C would stop it.

  5. 5Stop a background job

    kill %1

    Job numbers work with kill.

  6. 6Keep a job running after logout

    ./long-task.sh &
    disown -h %1

    Or start it with nohup.

  7. 7Show only stopped jobs

    jobs -s

    Forgotten paused jobs block logout ("There are stopped jobs").

  8. 8Use the job by name

    fg %tar

    The job whose command starts with tar.

  9. 9PIDs for other commands

    renice -n 10 -p $(jobs -p)

    Makes all your jobs nicer.

  10. 10Wait for all background jobs in a script

    for h in server1 server2; do ssh $h 'dnf -y upgrade' & done; wait

    Runs in parallel; wait waits for all.

Let op

  • Jobs belong to one shell. Another terminal does not see them.
  • A background job that wants input stops ("Stopped (tty input)").

Exitcodes

0 :: Done. 1 :: No such job.