Process is an instance of a #Program that is being executed. fork
System Call# could be used to create a new Process. The process will inherit all the environment variables from the parent process. In #c, this could be accessed via function getenv()
, which will either return a pointer to the specified environment variable or a NULL pointer, or third argument to the main function (shown below). The latter will be terminated with a NULL pointer.
int main(int argc, char *argv[], char *envp[]) {
...
}
It has the following structure, from top to bottom:
- stack (where the function call’s address linkage and data elements)
- heap (for dynamic memory allocation)
- uninitialised data
- initialised read-write data
- initialised read-only data
- text (contain machine instructions)
Note: In most cases, there will be a space between heap and stack in order to accommodate the growth of these two portions.
Every process has its own unique process ID (PID), which could be obtained via getid()
System Call#. We could get its parent’s PID too using getppid()
. The process will inherit the user ID and group ID, which could be inspected with getuid()
and getgid()
or geteuid()
and getegid()
(getting the effective user ID and group ID, usually is the same with the user ID and group ID).