Content
POSIX process management
Identification of processes
POSIX identifies each process by a unique integer called the process id of type pid_t
The function to get the id of the process that performs the call is
The function to get the id of the parent process is
The function to get the id of the real user is
The function to get the id of the actual group is
Environment of a process
The environment of a process consists of the list of variables that are passed to the process at the time you start your run
They are accessible through an external variable that points to a list of environment variables:
Some environment variables:
- HOME: working directory initial user
- LOGNAME: name of the user associated with the process
The function to get the value of an environment variable is char
Creation of processes
The function to create a process is
Returns the id of the child process to the parent process and 0 to the child process, will return -1 in case of failure
Creates a child process that runs the same program as the parent. Inherits open files (descriptors are copied)
The functions for running a different program (code) are:
As arguments path, executable file file and arg are used as executable arguments
Returns -1 in case of error. If successful it will not return any value
Changes the memory image of the process. The same process runs another program but keeps the files open
Termination of processes
The function to terminate a process is
As an argument state is used, which is the return code to the parent process
Ends the execution of the process
Closes all the file descriptors open
All the resources are released in the process
Waiting for the terminaciçon of a process
The functions to wait for the completion of a child process are:
As arguments state, the termination identifier of the child process, pid, process identifier, options, options identifier are used
Returns the identifier of the child process or -1 in case of error
Allows a parent process to wait until the end of the execution of a child process