linux - 如何等待进程子进程?

标签 linux posix exec fork wait

我执行通常的 fork + exec 组合:

int sockets [2];
socketpair (AF_LOCAL, SOCK_STREAM, 0, sockets);
int pid = fork ();

if (pid == 0) {
  // child
  dup2 (sockets[0], STDIN_FILENO);
  dup2 (sockets[0], STDOUT_FILENO);
  execvp (argv[0], argv);
  _exit (123);
}
// parent

close (sockets[0]);
// TODO wait and see if child crashes

是否可以等到子进程崩溃或开始等待 read(...)?

最佳答案

checkout waitpid

 pid_t waitpid(pid_t pid, int *stat_loc, int options);

来自

#include <sys/wait.h>

关于linux - 如何等待进程子进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1586030/

相关文章:

php - 执行或 Shell_exec : variables don't pass from php to the script

c -/dev/urandom 为 mmap() 提供随机地址

sql - 存储过程中 exec 内的临时表的作用域规则是什么?

PHP 5.3.2 和 Zend Framework session

c++ - C++ 内存不足 : write to file instead, 在需要时读取数据?

c - 来自 sys/stat.h 的 S_ISXXX(m) 宏出现问题

c++ - 在 C 和 C++ 中正确使用字符串存储

python - 如何将表示嵌套列表的字符串解析为实际列表?

linux - 将 MySQL 数据库传输到 Mac 的最佳方式?

linux - 如何通过 Bash 在 Linux 中设置重启后不变的时间?