• Aucun résultat trouvé

Process Control

Dans le document Language Reference (Page 74-77)

The term process refers to a program running under the operating system. A process consists of the code and data for the program and information about the status of the running program, such as the number of open files. Whenever you run a program at the DOS level, you start a process. In addition, you can start, stop, and manage processes from within a program by using the process control rou-tines.

The process control routines let you:

• Identify a process by a unique number (getpid)

• Stop a process (abort, exit, and _exit)

• Handle an interrupt signal (raise and signal)

• Start a new process (the exec and spawn families of routines, plus the system routine).

The declarations for all process control functions except raise and Signal are in the include file process.h. The declaration for the raise and signal function are in the signal.h include file.

Routine Use

abort Stops a process.

exec I Runs a child process, using an argument list.

execle

Runs a child process, using an argument list and a given environment.

Runs a child process, using the PATH variable and an argu-ment list.

Runs a child process, using the PATH variable and an argu-ment list.

Runs a child process, using an argument array.

Runs a child process, using an argument array and a given envi ronment.

Runs a child process, using the PATH variable and an argu-ment array.

Runs a child process, using the PATH variable, an argu-ment array, and a given environargu-ment.

Ends a process, flushing buffers and closing files.

Ends a process without flushing the buffers.

Gets a process identification number.

Runs functions at the normal or abnormal ending of a program.

Sends a signal to a program.

Handles an interrupt signal.

Starts a child process, using an argument list.

Starts a child process, using an argument list and a given environment.

Starts a child process, using the PATH variable and an argument list.

Starts a child process, using the PATH variable, an argu-ment list, and a given environargu-ment.

Starts a child process, using an argument array.

Starts a child process, using an argument array and a given environment.

Starts a child process, using the PATH variable and an argument array.

spawnvpe Starts a child process, using the PATH variable, an argu-ment array, and a given environargu-ment.

system Runs a DOS command.

The abort and _exit functions immediately end a process without flushing the stream buffers. The exit function ends a process after flushing the stream buffers.

The system function runs a given DOS command. The exec and spawn functions start up a new process, called the child process. The differ-ence between the exec and spawn routi nes is that the spawn routi nes

can return control from the child process to its caller (the parent process). Under DOS, both the parent process and the child process are present in memory unless you specify P _OVERLAY. Under OS/2, the parent and child mayor may not both be in memory, if swapping is enabled.

Under DOS in the exec routines, the child process overlays the parent process. Returning control to the parent process is impossible unless an error occurs when you attempt to start running the child process.

Under OS/2, exec is simulated. The child process does not actually overlay the parent in storage, but it is not possible to return control to the parent process, which ends as soon as the child starts.

There are eight forms each of the spawn and exec routines. The fol-lowing table summarizes the differences between the forms. The function names are in the first column. The second column specifies whether the current PATH setting locates the file to be run as the child process.

The third column describes the method for passing arguments to the child process. PaSSing an argument list means that you list the argu-ments to the child process as separate arguargu-ments in the exec or spawn call. Passing an argument array means that the arguments are in an array and a pointer to the array is passed to the child process. Use the argument-list method when the number of argu-ments is constant or is known when you compile. Use the argument-array method when you cannot tell the number of arguments until you run the program.

The last column specifies if the child process inherits the environ-ment settings of its parent or you must pass a pointer to a table of environment settings to set up a different environment for the child process.

Use of PATH Argument-Passing

Routine Setting Convention Environment execl, Uses PATH Argument list Pointer to

envi-spawn I ronment table

for child process passed as last argument.

execle, Uses PATH Argument list Pointer to

envi-spawn Ie ronment table

for child process passed as last argument execlp, Uses PATH Argument list Inherited from

spawnlp parent

execv, Does not Argument array Inherited from

spawnv use PATH parent

execve, Does not Argument array Pointer to

envi-spawnve use PATH ronment table

for child process passed as last argument execvp, Uses PATH Argument array Inherited from

spawnvp parent

execvpe, Uses PATH Argument array Pointer to

envi-spawnvpe ronment table

The run-time library has three search routines and one sort routine.

Routine

Performs a binary search.

Performs a linear search for a given value.

Performs a linear search of an array for a given value. If Isearch does not find the value in the array, it adds it to the array.

Performs a quick-sort.

Dans le document Language Reference (Page 74-77)