A program or command that is actually running on the computer is referred to as a process. Processes exist in parent-child hierarchies. A process started by a program or command is a parent process; a child process is the product of the parent process. A parent process can have several child processes, but a child process can have only one parent.
The system assigns a process identification number (PID number) to each process when it starts. If you start the same program several times, it will have a different PID number each time.
When a process is started on a system, the process uses a part of the available system resources. When more than one process is running, a scheduler that is built into the operating system gives each process its share of the computer's time, based on established priorities. These priorities can be changed by using the nice or renice commands.
Note: To change a process priority to a higher one, you must have root user authority. All users can lower priorities on a process they start by using the nice command, or on a process they have already started, by using the renice command.
This section describes the following procedures:
Processes that require a user to start them or to interact with them are called foreground processes. Processes that are run independently of a user are referred to as background processes. Programs and commands run as foreground processes by default. To run a process in the background, place an ampersand (&) at the end of the command name that you use to start the process.
Daemons are processes that run unattended. They are constantly in the background and are available at all times. Daemons are usually started when the system starts, and they run until the system stops. A daemon process performs system services and is available at all times to more than one task or user. Daemon processes are started by the root user or root shell and can be stopped only by the root user. For example, the qdaemon process provides access to system resources such as printers. Another common daemon is the sendmail daemon.
A zombie process is a dead process that is no longer executing but is still recognized in the process table (in other words, it has a PID number). It has no other system space allocated to it. Zombie processes have been killed or have exited and continue to exist in the process table until the parent process dies or the system is shut down and restarted. Zombie processes display as <defunct> when listed by the ps command.
You start a foreground process from a display station by either entering a program name or command name at the system prompt. After a foreground process has started, the process interacts with you at your display station until it is complete. This means no other interaction (for example, entering another command) can take place at the display station until the process is finished or you halt it.
A single user can run more than one process at a time, up to a default maximum of 40 processes per user.
To run a process in the foreground, type the name of the command with all the appropriate parameters and flags:
$ CommandName
Press Enter.
To run a process in the background, type the name of the command with all the appropriate parameters and flags, followed by an ampersand (&):
$ CommandName&
Press Enter.
When the process is running in the background, you can perform additional tasks by entering other commands at your display station.
Generally, background processes are most useful for commands that take a long time to run. However, because they increase the total amount of work the processor is doing, background processes also slow down the rest of the system.
Most processes direct their output to standard output, even when they run in the background. Unless redirected, standard output goes to the display device. Because the output from a background process can interfere with your other work on the system, it is usually good practice to redirect the output of a background process to a file or a printer. You can then look at the output whenever you are ready.
Note: Under certain circumstances, a process might generate its output in a different sequence when run in the background than when run in the foreground. Programmers might want to use the fflush subroutine to ensure that output occurs in the correct order regardless of whether the process runs in foreground or background.
As long as a background process is running, you can check its status with the ps command.
Any time the system is running, several processes are also running. You can use the ps command to find out which processes are running and to display information about those processes.
The ps command has several flags that enable you to specify which processes to list and what information to display about each process.
To show all processes running on your system, at the prompt, type:
ps -ef
Press Enter.
The system displays information similar to the following:
USER PID PPID C STIME TTY TIME CMD root 1 0 0 Jun 28 - 3:23 /etc/init root 1588 6963 0 Jun 28 - 0:02 /usr/etc/biod 6 root 2280 1 0 Jun 28 - 1:39 /etc/syncd 60 mary 2413 16998 2 07:57:30 - 0:05 aixterm mary 11632 16998 0 07:57:31 lft/1 0:01 xbiff mary 16260 2413 1 07:57:35 pts/1 0:00 /bin/ksh mary 16469 1 0 07:57:12 lft/1 0:00 ksh /usr/lpp/X11/bin/xinit mary 19402 16260 20 09:37:21 pts/1 0:00 ps -ef
The columns in the previous output are defined as follows:
USER | User login name |
PID | Process ID |
PPID | Parent process ID |
C | CPU utilization of process |
STIME | Start time of process |
TTY | Controlling workstation for the process |
TIME | Total execution time for the process |
CMD | Command |
In the previous example, the process ID for the ps -efcommand is 19402. Its parent process ID is 16260, the /bin/ksh command.
If the listing is very long, the top portion scrolls off the screen. To display the listing one page (screen) at a time, use the ps command piped to the pg command. At the prompt, type:
ps -ef | pg
Press Enter.
To show status information of all processes running on your system, at the prompt, type:
ps gv
Press Enter.
This form of the command lists a number of statistics for each active process. Output from this command looks similar to the following:
PID TTY STAT TIME PGIN SIZE RSS LIM TSIZ TRS %CPU %MEM COMMAND 0 - A 0:44 7 8 8 xx 0 0 0.0 0.0 swapper 1 - A 1:29 518 244 140 xx 21 24 0.1 1.0 /etc/init 771 - A 1:22 0 16 16 xx 0 0 0.0 0.0 kproc 1028 - A 0:00 10 16 8 xx 0 0 0.0 0.0 kproc 1503 - A 0:33 127 16 8 xx 0 0 0.0 0.0 kproc 1679 - A 1:03 282 192 12 32768 130 0 0.7 0.0 pcidossvr 2089 - A 0:22 918 72 28 xx 1 4 0.0 0.0 /etc/sync 2784 - A 0:00 9 16 8 xx 0 0 0.0 0.0 kproc 2816 - A 5:59 6436 2664 616 8 852 156 0.4 4.0 /usr/lpp/ 3115 - A 0:27 955 264 128 xx 39 36 0.0 1.0 /usr/lib/ 3451 - A 0:00 0 16 8 xx 0 0 0.0 0.0 kproc 3812 - A 0:00 21 128 12 32768 34 0 0.0 0.0 usr/lib/lpd/ 3970 - A 0:00 0 16 8 xx 0 0 0.0 0.0 kproc 4267 - A 0:01 169 132 72 32768 16 16 0.0 0.0 /etc/sysl 4514 lft/0 A 0:00 60 200 72 xx 39 60 0.0 0.0 /etc/gett 4776 pts/3 A 0:02 250 108 280 8 303 268 0.0 2.0 -ksh 5050 - A 0:09 1200 424 132 32768 243 56 0.0 1.0 /usr/sbin 5322 - A 0:27 1299 156 192 xx 24 24 0.0 1.0 /etc/cron 5590 - A 0:00 2 100 12 32768 11 0 0.0 0.0 /etc/writ 5749 - A 0:00 0 208 12 xx 13 0 0.0 0.0 /usr/lpp/ 6111 - T 0:00 66 108 12 32768 47 0 0.0 0.0 /usr/lpp/
See the ps command in the AIX 5L Version 5.2 Commands Reference for the complete syntax.
You can set the initial priority of a process to a value lower than the base scheduling priority by using the nice command to start the process.
Note: To run a process at a higher priority, you must have root user authority.
To set the initial priority of a process, type:
nice -n Number CommandString
where Number is in the range of 0 to 39, with 39 being the lowest priority. The nice value is the decimal value of the system-scheduling priority of a process. The higher the number, the lower the priority. If you use zero, the process will run at its base scheduling priority. CommandString is the command and flags and parameters you want to run.
See the nice command in the AIX 5L Version 5.2 Commands Reference for the complete syntax.
You can also use the smit nice command to perform this task.
You can change the scheduling priority of a running process to a value lower or higher than the base scheduling priority by using the renice command from the command line. This command changes the nice value of a process.
Note: To run a process at a higher priority or to change the priority for a process that you did not start, you must have root user authority.
To change the initial priority of a running process, type:
renice Priority -p ProcessID
where Priority is in the range of -20 to 20. The higher the number, the lower the priority. If you use zero, the process will run at its base scheduling priority. ProcessID is the PID for which you want to change the priority.
You can also use the smit renice command to perform this task.
If you start a foreground process and then decide that you do not want it to finish, you can cancel it by pressing INTERRUPT. This is usually Ctrl-C or Ctrl-Backspace. To find out what your INTERRUPT key is set to, see Listing Control Key Assignments for Your Terminal (stty Command).
Note: INTERRUPT (Ctrl-C) does not cancel background processes. To cancel a background process, you must use the kill command.
Most simple commands are not good examples for demonstrating how to cancel a process. They run so quickly that they finish before you have time to cancel them. The examples in this section, therefore, use a command that takes more than a few seconds to run: find / -type f. This command displays the path names for all files on your system. You do not need to study the find command in order to complete this section; it is used here simply to demonstrate how to work with processes.
In the following example, the find command starts a process. After the process runs for a few seconds, you can cancel it by pressing the INTERRUPT key:
$ find / -type f /usr/sbin/acct/lastlogin /usr/sbin/acct/prctmp /usr/sbin/acct/prdaily /usr/sbin/acct/runacct /usr/sbin/acct/sdisk /usr/sbin/acct/shutacct INTERRUPT (Ctrl-C) $ _
The system returns the prompt to the screen. Now you can enter another command.
It is possible for a process to be stopped but not have its process ID (PID) removed from the process table. You can stop a foreground process by pressing Ctrl-Z from the keyboard.
Note: Ctrl-Z works successfully in the Korn shell (ksh) and C shell (csh), but not in the Bourne shell (bsh).
This procedure describes how to restart a process that has been stopped with a Ctrl-Z.
Note: Ctrl-Z works successfully in the Korn shell (ksh) and C shell (csh), but not in the Bourne shell (bsh). To restart a stopped process, you must either be the user who started the process or have root user authority.
ps -ef
You might want to pipe this command through a grep command to restrict the list to those processes most likely to be the one you want to restart. For example, if you want to restart a vi session, you could type:
ps -ef | grep vi
Press Enter.
This command would display only those lines from the ps command output that contained the word vi. The output would look something like this:UID PID PPID C STIME TTY TIME COMMAND root 1234 13682 0 00:59:53 - 0:01 vi test root 14277 13682 1 01:00:34 - 0:00 grep vi
kill -19 1234
Substitute the PID of your process for the 1234. The -19 indicates the CONTINUE signal. This command restarts the process in the background. If the process can run in the background, you are finished with the procedure. If the process must run in the foreground (as a vi session would), you must proceed with the next step.
fg 1234
Once again, substitute the PID of your process for the 1234. Your process should now be running in the foreground. (You are now in your vi edit session).
You can set up a process as a batch process to run in the background at a scheduled time. The at and smit commands let you enter the names of commands to be run at a later time and allow you to specify when the commands should be run.
Note: The /var/adm/cron/at.allow and /var/adm/cron/at.deny files control whether you can use the at command. A person with root user authority can create, edit, or delete these files. Entries in these files are user login names with one name to a line. The following is an example of an at.allow file:root nick dee sarah
If the at.allow file exists, only users whose login names are listed in it can use the at command. A system administrator can explicitly stop a user from using the at command by listing the user's login name, in the at.deny file. If only the at.deny file exists, any user whose name does not appear in the file can use the at command.
You cannot use the at command if any one of the following is true:
If the at.allow file does not exist and the at.deny file does not exist or is empty, only someone with root user authority can submit a job with the at command.
The at command syntax allows you to specify a date string, a time and day string, or an increment string for when you want the process to run. It also allows you to specify which shell or queue to use. The following examples show some typical uses of the command.
For example, if your login name is joyce and you have a script named WorkReport that you want to run at midnight, do the following:
at midnight
WorkReport^D
After you press Ctrl-D, the system displays information similar to the following:
job joyce.741502800.a at Fri Jul 6 00:00:00 CDT 2002.
The program WorkReport is given the job number joyce.741502800.a and will run at midnight July 6.
To list the programs you have sent to be run later, type:
at -l
The system displays information similar to the following:
joyce.741502800.a Fri Jul 6 00:00:00 CDT 2002
See the at command in the AIX 5L Version 5.2 Commands Reference for the exact syntax.
You can list all scheduled processes by using the -l flag with the at command or with the atq command. Both commands give the same output, but the atq command can order the processes by the time the at command was issued and can display just the number of processes in the queue.
You can list all scheduled processes in the following ways:
For user restrictions on using the at command, see the Note inScheduling a Process for Later Operation (at Command).
To list the scheduled processes, type:
at -l
This command lists all the scheduled processes in your queue. If you are a root user, this command lists all the scheduled processes for all users. For complete details of the syntax, see the at command.
To list all scheduled processes in the queue, type:
atq
If you are a root user, you can list the scheduled processes in a particular user's queue by typing:
atq UserName
To list the number of scheduled processes in the queue, type:
atq -n
You can remove a scheduled process with the at command using the -r flag. For user restrictions on using the at command, see the Note inScheduling a Process for Later Operation (at Command).
at -r ProcessNumber
You can also use the smit rmat command to perform this task.
If INTERRUPT does not halt your foreground process or if you decide, after starting a background process, that you do not want the process to finish, you can cancel the process with the kill command. Before you can cancel a process using the kill command, you must know its PID number. The general format for the kill command is as follows:
kill ProcessID
Note: To remove a process, you must have root user authority or be the user who started the process. The default signal to a process from the kill command is -15 (SIGTERM).
Note: To remove a zombie process, you must remove its parent process.
ps -l | grep vi
$ find / -type f > dir.paths & [1] 21593 $ ps PID TTY TIME COMMAND 1627 pts3 0:00 ps 5461 pts3 0:00 ksh 17565 pts3 0:00 -ksh 21593 pts3 0:00 find / -type f $ kill 21593 $ ps PID TTY TIME COMMAND 1627 pts3 0:00 ps 5461 pts3 0:00 ksh 17565 pts3 0:00 -ksh [1] + Terminated 21593 find / -type f > dir.paths &
The command kill 21593 ends the background find process, and the second ps command returns no status information about PID 21593. The system does not display the termination message until you enter your next command, unless that command is cd.
The kill command lets you cancel background processes. You might want to do this if you realize that you have mistakenly put a process in the background or a process is taking too long to run.
See the kill command in the AIX 5L Version 5.2 Commands Reference for the complete syntax.
The kill command can also used in smit by typing:
smit kill