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
disown
Niets past bij dit filter.
Voorbeelden 10
$ als gewone gebruiker# als root (of met sudo)
1Start a job in the background
sleep 600 & [1] 4123Job number 1, PID 4123.
2List the jobs
jobs -l [1]+ 4123 Running sleep 600 &-l adds the PID.
3Pause and continue in the background
tar -czf /tmp/home.tgz ~ ^Z [1]+ Stopped tar -czf /tmp/home.tgz ~ bgCtrl+Z, then bg: the terminal is free again.
4Bring a job back
fg %1Now Ctrl+C would stop it.
5Stop a background job
kill %1Job numbers work with kill.
6Keep a job running after logout
./long-task.sh & disown -h %1Or start it with nohup.
7Show only stopped jobs
jobs -sForgotten paused jobs block logout ("There are stopped jobs").
8Use the job by name
fg %tarThe job whose command starts with tar.
9PIDs for other commands
renice -n 10 -p $(jobs -p)Makes all your jobs nicer.
10Wait for all background jobs in a script
for h in server1 server2; do ssh $h 'dnf -y upgrade' & done; waitRuns in parallel;
waitwaits for all.
Niets past bij dit filter.
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.