FLOPPIX Home | FAQ | Download | Labs | ToC | Back |  Next 

Managing processes


Notes:

Because unix is a multi-tasking operating system, each user can have many commands running at one time. Using the bash shell, users can run programs in the foreground (interacting with the terminal) or in the background (running but not interacting with the terminal). If a job is running in the background, the user can continue to work on other tasks at the command prompt.

New commands:

  1. ps - displays a list of your processes. Options:
  2. If a process is running in the foreground, [crtl-z] suspends it.
  3. To start a process in the background, end the command line with &
    eg:  cp * /tmp &
  4. bg - backgrounds a process (suspend it first)
  5. jobs - lists background processes
  6. fg - foregrounds a process (if there is more than one background task, fg %2 will foreground job 2)
  7. kill - terminates a process.
    Note: sometimes killing a process can have unexpected side effects. Killing the process can leave behind temporary or locked files.
  8. sleep - pauses a specified number of seconds


Exercises:

  1. Use the ps command:
    1. Enter the command ps au
    2. What processes are running on tty1?
    3. What processes are running on tty2?
    4. Switch to virtual console 2, login as alterego and enter the command ps au again.
    5. What processes are running on tty1?
    6. What processes are running on tty2?
    7. Logout on virtual console 2; switch back to virtual console 1.
    8. What processes are running on tty1?
    9. What processes are running on tty2?
    10. Enter the command: ps aux
    11. What additional processes are running?
       
  2. Suspend, background, foreground, kill
    1. Start links.
    2. Suspend it.
    3. Enter the command: (sleep 60 ; sleep 60 ; ls -l > flist)
      (make sure that you include the brackets; this command means: wait 60 seconds, wait 60 seconds, save the output from ls -l in the file flist).
    4. Suspend this command.
    5. Back |ground the sleep process started in step 3.
    6. Foreground links
    7. Suspend links
    8. Kill links
    9. Check to see if the sleep command line has finished


Questions and Answers:

  1. What command lists all of your processes?
     
    Answer: ps
     
  2. What command lists all running processes?
     
    Answer ps aux
     
  3. If the status of one of your processes is [Suspended], how do you restart it?
     
    Answer:
    fg
     
  4. How would you run ( sleep 60 ; ls -l > listing ) as a background job?
     
    Answer:
    ( sleep 60 ; ls -l > listing ) &
     
  5. How do you background a running process?
     Answer: [Ctrl-z] ;  bg
     
  6. If a process is running in the background, how do you move it to the foreground?
     
    Answer:
    fg
     
  7. How do you terminate a process, pid 345 and job number 4?
     
    Answer:
    kill %4 or kill 345
  8. If job 4 does not respond to the normal kill command command, what command will kill it?
     
    Answer: kill -9 %4

Copyright © L.M.MacEwan
FLOPPIX Home | FAQ | Download | Labs | ToC | Back |  Next