[Introduction to UNIX for Web Developers]
[Spacer] [Table of Contents]
[Next Page]
[Previous Page]
[Spacer]
Managing Processes
As you have seen, it is easy to run programs (or utilities) on UNIX systems. Essentially, you just type the name of the command at the command line at the program runs.

In this section we will discuss managing those programs that you run. However, before we do that, we should say a few more things about commands and how to run them correctly. As we said, you execute a command by typing the name of the command at the command line. But what exactly is the name? Well the name refers not only to the name of the utility, but also to its location on the system. A command's name is really its "pathname".

For example, when you run the "ls" utility, you are actually running the "usr/bin/ls" program. Fortunately, UNIX typically already knows to look for programs in "/usr/bin", so you do not need to specify the directory explicitly. (We will talk more about how UNIX knows about "/usr/bin" later).

But you can also try running "ls" by calling it explicitly from "/usr/bin" by typing something like:

/usr/bin/ls

at the command line. But what if the program is not located in the "/usr/bin" directory? What happens if UNIX cannot find the program by itself.

Well, the first thing you should do is find the program. Typically you will use the "which" utility or the "whereis" utility to find the location of the program. Then you can execute it explicitly with the full pathname.

[which Example]

Another useful thing to know is that you can always stop an application from running by hitting CONTROL-C (or CONTROL-Z to suspend).

Further, if you want to run an application in the background, you need only append a "&" to the end of the command when you execute it. When you do this, UNIX will execute the command by itself and allow you to continue working from the command line.

This is very useful when you have a utility or application that needs a lot of time to complete. You do not want to have to sit there and wait for the application to finish while you could be doing other work. Sometimes it is easier to simply open another shell with telnet or rlogin, but often, you don't want to clutter up your desktop and it is reasonable just to run the command in the background.

In the following example, we run a lengthy spell check on a large file in the background.

[background Example]

Finally, the "nohup" utility is very useful when you want a utility to continue to run even after you have logged out. Without the "nohup" utility, your applications would all quit when you log out. If you use the nohup utility, they will run until complete. Consider the following example in which we put a sort operation on "nohup" and log out. When you log back in, the sort will have finished without you. (Don't forget that you need to run "nohup" applications in the background)

[nohup Example]

Once you are running an application, or several applications, however, you will need to be aware of several other utilities that help you manage running applications.

The first such utility is the "ps" utility that allows you to get a listing of processes currently being executed by the UNIX system. By default the utility displays four columns. Essentially, this information let's you know exactly what UNIX is tasked with.

  • PID = ID number of the process that the kernel uses to keep track of it.
  • TTY = Associated terminal
  • TIME = CPU time spent running the process.
  • CMD = Name of the command.

The "ps" utility comes with several useful options, some of which are listed below.

Command Explanation
-e Displays ALL processes
-f Gives the full process list including the command line arguments
-l Provides a long listing
-uusers Reports activity of given users.

Check out the examples of "ps" below:

[ps Command Example]

One thing to keep in mind is that "ps -ef" usually provides a lot more info than you want since it reports on all users. Thus, it is usual to see the utility used with grep such as in the following example

[Spacer]
[Grep and ps]

Once you know what processes are currently running, you can stop them by using the "kill" utility. The "kill" utility takes a PID value and terminates the associated application. Look at the following example in which we accidentally start a find operation which will take forever and kill it from another window:

[Spacer]
[kill]

[Spacer] There are actually several other utilities to manage processes, but we will not cover them here since they are primarily sys admin tools and not things you will be doing. The "ps" and the "kill" should provide you with enough tools to do the jobs you will be interested in doing.

Previous | Next | Table of Contents