本文共 3461 字,大约阅读时间需要 11 分钟。
[root@db-172-16-3-150 zzz]# cat a.c#include#include #include const int MAX_PROCS = 5;int main() { fprintf(stdout, "this is parent process, fork start.pid:%i, ppid:%i\n", (int)(getpid()), (int)(getppid())); int i; pid_t p; for(i=0;i
[root@db-172-16-3-150 zzz]# cat a.c#include#include #include #include const int MAX_PROCS = 5;int main() { fprintf(stdout, "this is parent process, fork start.pid:%i, ppid:%i\n", (int)(getpid()), (int)(getppid())); fprintf(stdout, "getenv(TEST):%s\n", getenv("TEST")); int i; pid_t p; for(i=0;i
NAME fork - create a child processSYNOPSIS #includevfork :#include pid_t fork(void);DESCRIPTION fork() creates a child process that differs from the parent process only in its PID and PPID, and in the fact that resource utilizations are set to 0. File locks and pending signals are not inherited. Under Linux, fork() is implemented using copy-on-write pages, so the only penalty that it incurs is the time and memory required to duplicate the parent’s page tables, and to create a unique task structure for the child.
NAME vfork - create a child process and block parentSYNOPSIS #includegetpid, getppid :#include pid_t vfork(void);LINUX DESCRIPTION vfork(), just like fork(2), creates a child process of the calling process. For details and return value and errors, see fork(2). vfork() is a special case of clone(2). It is used to create new processes without copying the page tables of the parent process. It may be useful in performance sensitive applications where a child will be created which then immediately issues an execve(). vfork() differs from fork() in that the parent is suspended until the child makes a call to execve(2) or _exit(2). The child shares all memory with its parent, including the stack, until execve() is issued by the child. The child must not return from the current function or call exit(), but may call _exit(). Signal handlers are inherited, but not shared. Signals to the parent arrive after the child releases the par- ent’s memory.
NAME getpid, getppid - get process identificationSYNOPSIS #include#include pid_t getpid(void); pid_t getppid(void);DESCRIPTION getpid() returns the process ID of the current process. (This is often used by routines that generate unique temporary filenames.) getppid() returns the process ID of the parent of the current process.
转载地址:http://cjmxl.baihongyu.com/