Process management

Process management

A process is the execution of a program; most UNIX System V commands execute as separate processes. Each process is a distinct entity, able to execute and terminate independently of all other processes. Each user can have many processes in the system simultaneously. In fact, it is not always necessary for the user to be logged into the system while those processes are executing.

In UnixWare, the operating system supports a schedulable entity called a ``lightweight process'' (LWP). Each process contains one or more LWPs. LWPs allow multiple threads of control within a single process. The Threads Library provides interfaces with which applications may be multithreaded. See ``Threads'' for information about threads and LWPs. When a process does not explicitly create any new LWPs, it contains one LWP and has the same semantics that a process had in previous releases.

Whenever you execute a command in the UNIX system you are initiating a process that is numbered and tracked by the operating system. A flexible feature of the UNIX system is that processes can be generated by other processes. This happens more than you might ever be aware of. For example, when you log in to your system you are running a process, very probably the shell. If you then use an editor such as vi, take the option of invoking the shell from vi, and execute the ps command, you will see a display something like the one in the following figure (which shows the results of a ps -f command):

   abc	24210	1	0	06:13:14	tty29	0:05	-sh
   abc	24631	24210	0	06:59:07	tty29	0:13	vi c2.uli
   abc	28441	28358	80	09:17:22	tty29	0:01	ps -f
   abc	28358	24631	2	09:15:14	tty29	0:01	sh -i

Process status

As you can see, user abc (who went through the steps described above) now has four processes active. It is an interesting exercise to trace the chain that is shown in the Process ID (PID) and Parent Process ID (PPID) columns. The shell that was started when user abc logged on is process 24210; its parent is the initialization process (process ID 1). Process 24210 is the parent of process 24631, and so on.

The four processes in the example above are all UNIX system shell-level commands, but you can spawn new processes from your own program. You might think, ``Well, it's one thing to switch from one program to another when I'm at my terminal working interactively with the computer; but why would a program want to run other programs, and if one does, why wouldn't I just put everything together into one big executable module?''

Overlooking the case where your program is itself an interactive application with diverse choices for the user, your program may need to run one or more other programs based on conditions it encounters in its own processing. (If it is the end of the month, go do a trial balance, for example.) The usual reasons why it might not be practical to create one large executable are:

Suffice it to say, there are legitimate reasons why this creation of new processes might need to be done. There are two ways to do it:

Next topic: Program execution - exec

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004