Sei sulla pagina 1di 3

Job Control

Objectives:
1. 2. 3. 4. Define how jobs and processes works in Linux. List and identify the processes running in the Linux Operating System. Select the most important processes in Linux. Apply the Linux commands as well as bash commands to monitor and manage Linux processes.

Job
Every command you give in Linux is a job that is executed. A job can be suspended, placed in the background, moved back to the foreground or terminated. Job control is the ability to stop, restart, and background a running process. The shell lets you put & on the end of a command line to start it in the background. You can hit Ctrl+Z to suspend a running foreground job. Suspended and backgrounded jobs are given numbers by the shell. Job control commands include jobs, fg and bg

jobs
The jobs built-in prints a listing of active jobs and their job numbers: $ jobs [1] Stopped vim index.html [2] Running mozilla & [3]+ Stopped man ls Job numbers are given in square brackets o But when you use them with other job-control built-ins, you need to write them with percent signs, as in %1. The jobs marked + and may be accessed as %+ or %- as well as by number. o %+ is the shells idea of the current job the most recently active job o %- is the previous current job

fg
Brings a backgrounded job into the foreground. Re-starts a suspended job, running it in the foreground. fg %1 will foreground job number 1 fg with no arguments will operate on the current job.

bg
Re-starts a suspended job, running it in the background bg %1 will background job number 1

bg with no arguments will operate on the current job For example, after running gv and suspending it with Ctrl+z, use bg to start it running again in the background. You can use screenshots to support your answer.

Exercises.

1. Essay. a. Start a process by running man bash and suspend it with Ctrl+Z. Describe your observation. b. Run xclock in the background, using &. Specify the exact command you used. c. Use jobs to list the backgrounded and stopped processes. Record your output. d. Use the fg command to bring man into the foreground, and quit it from it as normal. Specify the command and describe your observation. e. Use the fg command to foreground xclock, terminate it with Ctrl+c. Specify the commands used and describe your observation. f. Run xclock again but this time without &. Describe the outcome of the command. g. Try suspending xclock with Ctrl+z and describe what happens. h. Put xclock into the background using bg. Specify the command used.

2. Essay. a. Execute the command specified in the box. $ sleep Ctrl + Z Specify the output. b. What does the sleep command do? c. How does Ctrl+Z affects the previous command? 3. How would you move the stopped job in item 2 to the background. 4. Execute the command exactly as specified in the box. $ sleep 250 Ctrl+Z $ sleep 240 Ctrl +Z $ sleep 230 Ctrl+Z $ jobs a. Describe your observation on the series of commands you entered. b. Specify the output of jobs.

5. Referring to item 4, how would you move the second active job to the background. 6. Run gedit. This should run gedit in the foreground. You will not be able to use the shell. Then try suspending gedit with Ctrl+Z. a. What happened when you executed Ctrl+Z? b. How would you put gedit into the background?