Process Control



  • Whenever an executable file gets run, a process is created.
  • tcsh has some features to manage your processes.
  • Most of these features are only "interesting" for processes that run a long time.
  • Using the rm command creates a process to remove the file(s) you ask it to remove. But the rm process runs so fast you don't get much of a chance to control it.
  • Something like the editor vi is a process that runs for as long as you are editing the file.
  • If you have a process running and would like to make it die immediately, most processes can be killed with control-C.
  • If control-C doesn't work, a stronger thing to try is control-\
  • If that doesn't work, more drastic measures (covered later) are needed.
  • If you have a process running and would like to make it stop temporarily (e.g. you are in the editor but want to check what time it is) you can use control-Z to suspend the process.
  • This will bring you back to tcsh and you will have a shell prompt.
  • To restart the stopped job, use fg command to foreground the most recently stopped job.
  • Just a % on a command line is the same as fg.
  • You can start up and then stop several processes.
  • The command jobs will list all the jobs tcsh has started for you:
    % jobs
    [1]  - Suspended            vi main.c
    [2]  + Suspended            vi main.h
  • The + marks the most recently stopped job, - the next-most-recently stopped job.
  • You can start the job marked with - with command %-.
  • You can start up any specific job number with %n or fg n where n is the number of the job.
  • If you want to try to get rid of a job without starting it up again, you can use the kill command.
  • You usually need to use argument -9 with kill and specify which job to kill by %n. For example, to kill job number 1:
    % kill -9 %1
  • tcsh will normally not let you log off when you still have stopped jobs running. Just use the jobs command to see what jobs you left stopped and either use fg to bring them to the foreground so you can then close them gracefully, or use kill to kill them ungracefully.
  • Each process on a computer has a unique number to keep track of it called the process ID.
  • Some commands to handle processes need that process ID number.
  • The command jobs with the l flag will list process ID numbers too:
    % jobs -l
    [1]  - 19465 Stopped (user)       vi main.c
    [2]  + 19466 Stopped (user)       vi main.h
  • Long-running jobs can be run in the background.
  • For normal commands run from the command line, tcsh will wait for the command to finish before giving the prompt back to you.
  • You can end a command line with the & character to make that command run in the background.
  • tcsh will print a few numbers to your screen (the job number and process ID) and then immediately give you another prompt.
  • Background jobs show up in the jobs listing, but their status is Running.
  • When background jobs finish, tcsh prints a message on your screen just before it gives you a prompt.
  • If you are idle at your terminal, you won't see any message. This annoys most people.
  • You can set the shell variable notify to have shell report when a background job finishes even if your terminal is idle.
  • If you log off with jobs running in the background, they are left running.
  • If you log back in later, they won't be listed with jobs because they weren't started by this shell.
  • You can get a listing of processes with the process list command, ps.
  • ps with no arguments will list only processes for your current login session (ones associated with your current terminal).
  • Use ps -u username to list all processes owned by username on the system:
    % ps
       PID TTY      TIME COMD
     21372 pts/2    0:00 ps
     21316 pts/2    0:01 csh
    % ps -u kensmith
       PID TTY      TIME COMD
     21373 pts/2    0:00 ps
     19466 pts/27   0:00 vi
     15954 pts/27   0:01 csh
     19465 pts/27   0:00 vi
     21316 pts/2    0:01 csh
  • This is one of the commands with extreme differences between the Sys-V version and the Berkeley version.
  • The format of /usr/ucb/ps listing is different and no special flag is needed to see all the processes you own:
    % /usr/ucb/ps
       PID TT       S  TIME COMMAND
     21316 pts/2    S  0:00 -csh
     21382 pts/2    O  0:00 /usr/ucb/ps
     15954 pts/27   S  0:00 -csh
     19465 pts/27   T  0:00 vi main.c
     19466 pts/27   T  0:00 vi main.h
  • The command man ps shows you the manual page for the Sys-V version of ps.
  • On Solaris systems, you can see the manual page for the Berkeley version by looking in section 1B of the manual with:
    % man -s 1b ps
  • On Solaris systems, commands in /usr/ucb are described in section 1B of the manual.