文档介绍:Ch4 Linux System Programming – Process & IPC
Jianjian SONG
Software Institute, Nanjing University
Oct, 2004
Content
Process & process environment
Process Control
Process identifier, fork, exec…
Process relationship
Signal
Inter-munication (IPC)
Pipe, FIFO
semaphore, shared memory, message queue
Daemon
Thread
1. Process & Process Environment
What is a process?
Program and process
Process: an address space with one or more threads executing within that address space, and the required system resources for those threads. (SUSv3)
The startup of a process
System call “fork”
Process resources
struct task_struct
System space stack
…
System call “exec”
The entry of C programs
System stack
The entry of C programs
crt0./ld
main function
function prototype:
int main(int argc, char *argv[]);
The termination of a process
Five ways of terminating a process
Normal termination
Return from “main” function
Call “exit” function
Call “_exit” function
Abnormal termination
Call “abort” function
Terminated by a signal
exit & _exit functions
Function prototype:
#include <>
void exit(int status);
#include <>
void _exit(int status);
Exit status
Difference
_exit is corresponding to a system call, while “exit” is a library function.
_exit terminate a process immediately.
Exit handler
atexit function
Register a function to be called at normal program termination.
Prototype:
#include <>
int atexit(void (*function)(void));
on_exit function
Example