Create shell jobs and use mode of the jobs commands to manage the jobs

In this example four jobs are created then use fg, bg, ctrl z, ctrlz to manage the jobs.

If you want to learn more about jobs use below link:

https://linuxgeekseasywords.blogspot.com/2022/09/managing-processes.html


 [root@geeks ~]# sleep 3212 &   first job/process in the background

[1] 4481

[root@geeks ~]# sleep 43289 & second job/process in the background

[2] 4484

[root@geeks ~]# dd if=/dev/zero of=/dev/null &  third job/process in the background

[3] 4485

[root@geeks ~]# dd if=/dev/zero of=/dev/null &  fourth job/process in the background

[4] 4486

[root@geeks ~]# jobs  command to see background jobs

[1]   Running                 sleep 3212 &

[2]   Running                 sleep 43289 &

[3]-  Running                 dd if=/dev/zero of=/dev/null &

[4]+  Running                 dd if=/dev/zero of=/dev/null &

[root@geeks ~]# fg 2 it means job#2 bring in foreground and will use ctrl z to temporary stop it and it will go back in the background

sleep 43289

^Z

[2]+  Stopped                 sleep 43289

[root@geeks ~]# bg 2 bg means background bg 2 means run jobs 2 in the background(bg)

[2]+ sleep 43289 &

[root@geeks ~]# jobs  to see all jobs status

[1]   Running                 sleep 3212 &

[2]   Running                 sleep 43289 &

[3]-  Running                 dd if=/dev/zero of=/dev/null &

[4]+  Running                 dd if=/dev/zero of=/dev/null &

[root@geeks ~]# fg 3 job 3 bring in the foreground means in shell then use ctrl c to cancel it

dd if=/dev/zero of=/dev/null

^C128523643+0 records in

128523642+0 records out

65804104704 bytes (66 GB, 61 GiB) copied, 643.001 s, 102 MB/s


[root@geeks ~]# jobs  job 3 we cancel now only 3 jobs left

[1]   Running                 sleep 3212 &

[2]-  Running                 sleep 43289 &

[4]+  Running                 dd if=/dev/zero of=/dev/null &

[root@geeks ~]# fg 1 bring job 1 in the foreground and then stop it with ctrl z

sleep 3212

^Z

[1]+  Stopped                 sleep 3212

[root@geeks ~]# jobs  status of jobs #1 is stopped and 2 and 4 are on running mode

[1]+  Stopped                 sleep 3212

[2]   Running                 sleep 43289 &

[4]-  Running                 dd if=/dev/zero of=/dev/null &


Comments