Foreground & Background Jobs in Red Hat
The bash shell also provides ways for you to change whether a process is running in the foreground, the background, or at all, from the shell prompt. Some additional job control related shell commands are:
1. Ctrl+c: Terminate the foreground process. This causes the foreground process to exit completely.
2. Ctrl+z: Suspend the foreground process. This causes the foreground process to stop executing and returns you to shell prompt. The program will stay in memory, hanging. From here the process can be back grounded or killed, but if you do nothing it will just wait, detached from the shell, until the shell exits.
3. jobs: list back grounded and stopped process associated with this shell prompt.
4. fg: Send a job to the foreground. Only one process can run in the foreground in a shell. If no argument is given, it will foreground the current job (shown with a + in the output of jobs). Pass fg the job ID to manage jobs other than the current job:
[student@serverx ~]$ sleep 3000 &
[1] 22252
[student@serverx ~]$ sleep 4000 &
[1] 22253
[student@serverx ~]$ sleep 5000 &
[1] 22254
[student@serverx ~]$ jobs
[1] Running sleep 3000&
[2]- Running sleep 4000&
[3]+ Running sleep 5000&
[student@serverx ~]$ fg
sleep 5000
ctrl+c
[student@serverx ~]$ jobs
[1]- Running sleep 4000&
[2]+ Running sleep 5000&
[student@serverx ~]$ fg 1
sleep 3000
5. bg: Send a job to the background. Many jobs can run in the background in a singel shell, if no argument is given, bg will background the current job (just like fg foregrounds the current job) as through the job had been started with &.
The bash shell also provides ways for you to change whether a process is running in the foreground, the background, or at all, from the shell prompt. Some additional job control related shell commands are:
1. Ctrl+c: Terminate the foreground process. This causes the foreground process to exit completely.
2. Ctrl+z: Suspend the foreground process. This causes the foreground process to stop executing and returns you to shell prompt. The program will stay in memory, hanging. From here the process can be back grounded or killed, but if you do nothing it will just wait, detached from the shell, until the shell exits.
3. jobs: list back grounded and stopped process associated with this shell prompt.
4. fg: Send a job to the foreground. Only one process can run in the foreground in a shell. If no argument is given, it will foreground the current job (shown with a + in the output of jobs). Pass fg the job ID to manage jobs other than the current job:
[student@serverx ~]$ sleep 3000 &
[1] 22252
[student@serverx ~]$ sleep 4000 &
[1] 22253
[student@serverx ~]$ sleep 5000 &
[1] 22254
[student@serverx ~]$ jobs
[1] Running sleep 3000&
[2]- Running sleep 4000&
[3]+ Running sleep 5000&
[student@serverx ~]$ fg
sleep 5000
ctrl+c
[student@serverx ~]$ jobs
[1]- Running sleep 4000&
[2]+ Running sleep 5000&
[student@serverx ~]$ fg 1
sleep 3000
5. bg: Send a job to the background. Many jobs can run in the background in a singel shell, if no argument is given, bg will background the current job (just like fg foregrounds the current job) as through the job had been started with &.
Comments
Post a Comment