wait&exec

转载 2007年09月18日 13:23:00
wait, waitpid - wait for process to change state

Synopsis

#include <sys/types.h>
#include <sys/wait.h>

pid_t wait(int *status);
pid_t waitpid(pid_t pid, int *status, int options);
int waitid(idtype_t idtype, id_t id ", siginfo_t *" infop ", int " options );

Description

All of these system calls are used to wait for state changes in a child of the calling process, and obtain information about the child whose state has changed. A state change is considered to be: the child terminated; the child was stopped by a signal; or the child was resumed by a signal. In the case of a terminated child, performing a wait allows the system to release the resources associated with the child; if a wait is not performed, then terminated the child remains in a "zombie" state (see NOTES below).

If a child has already changed state, then these calls return immediately. Otherwise they block until either a child changes state or a signal handler interrupts the call (assuming that system calls are not automatically restarted using the SA_RESTART flag of sigaction(2)). In the remainder of this page, a child whose state has changed and which has not yet been waited upon by one of these system calls is termed waitable.

wait() and waitpid()

The wait() system call suspends execution of the current process until one of its children terminates. The call wait(&status) is equivalent to:
waitpid(-1, &status, 0);

The waitpid() system call suspends execution of the current process until a child specified by pid argument has changed state. By default, waitpid() waits only for terminated children, but this behaviour is modifiable via the options argument, as described below.

The value of pid can be:

< -1
meaning wait for any child process whose process group ID is equal to the absolute value of pid.
-1
meaning wait for any child process.
0
meaning wait for any child process whose process group ID is equal to that of the calling process.
> 0
meaning wait for the child whose process ID is equal to the value of pid

8.10. exec Functions

We mentioned in Section 8.3 that one use of the fork function is to create a new process (the child) that then causes another program to be executed by calling one of the exec functions. When a process calls one of the exec functions, that process is completely replaced by the new program, and the new program starts executing at its main function. The process ID does not change across an exec, because a new process is not created; exec merely replaces the current processits text, data, heap, and stack segmentswith a brand new program from disk.

相关文章推荐

python的os模块fork、wait、system、exec、popen、exit函数讲解

虽然进程可在单独的内存空间中执行,但除非这些Python进程在单独的处理器上执行,否则,实际并不是“同时”运行的。是由操作系统把处理器的时间片分配给一个进程,用完时间片后就需退出处理器等待另一个时间片...

进程控制开发[fork() exec exit _exit wait waitpid 守护进程]

第七章 进程控制开发[fork() exec exit _exit wait waitpid 守护进程] 转:http://www.cnblogs.com/jimwind/archi...
  • lcathm
  • lcathm
  • 2016年04月15日 14:54
  • 479

Linux下进程相关:fork(),wait(),exec()

Linux下进程创建,fork(),wait()等的使用
  • OCTODOG
  • OCTODOG
  • 2017年04月13日 11:37
  • 800

进程(2)—— wait()/waitpid()、vfork+exec

进程之间的调度(如何让父进程等待子进程) wait() waitpid()就是进程之间的调度函数 pid_t wait(int* status) 用于 父进程等待子进程的结束...

linux进程知识 程序存储、crontab、fork与vfork、exec、_exit()、wait()与waitpid()、孤儿和僵尸

一、程序存储       经常被问到进程与线程的区别,今天有人问程序与进程的区别,一下子还真没反应过来   。程序只是一组指令的有序集合,它本身没有任何运行的含义,它只是一个静态的实体。...

进程控制之 fork、wait、exec族函数 及进程资源控制

一,fork //头文件 #include //函数定义 pid_t fork( void ); 返回值:子进程中返回0,父进程中返回子进程ID,出错返回-1函数说明:一个现有进程可以调用for...

linux进程知识 程序存储、crontab、fork与vfork、exec、_exit()、wait()与waitpid()、孤儿和僵尸

一、程序存储       经常被问到进程与线程的区别,今天有人问程序与进程的区别,一下子还真没反应过来   。程序只是一组指令的有序集合,它本身没有任何运行的含义,它只是一个静态的实体。而进程则...

linux进程控制函数--fork,exec,exit,wait,sleep

1.fork 在linux系统中,用户创建进程的唯一方法就是使用系统调用fork,大概要进行下面的操作。 .分配表项,一个用户的进程项是有限的; .创建子进程的进程标识号; .复制父进程中的项...

多进程函数系列fork(), wait(), exec()系列,system(), posix_spawn()实例详解

多进程函数系列fork(), wait(), exec()系列,system(), posix_spawn()实例详解

系统调用wait、waitpid和exec函数

本文介绍了Linux下的进程的一些概念,并着重讲解了与Linux进程管理相关的重要系统调用wait,waitpid和exec函数族,辅助一些例程说明了它们的特点和使用方法。 1.7 背景 在前面的...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:wait&exec
举报原因:
原因补充:

(最多只允许输入30个字)