叉的和现有的主题? [英] fork and existing threads?

查看:79
本文介绍了叉的和现有的主题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux系统中,没有子进程查看现有线程方式与父进程一样吗?

On a linux system, does the child process view the existing threads the same way as the parent process ?

int main() {

  //create thread 1

  int child_pid = fork();

  if ( 0 == child_pid)
  {
       ..
  }
  else
  {
       ..
  }

由于整个地址空间被复制为子过程中,会发生什么情况的线程的状态。如果在上述段中的线程1在等待一个条件信号什么。它是在子进程的等待状态中呢?

Since the whole address space is copied for the child process, what happens to the state of the threads. What if the thread 1 in the above segment is waiting on a conditional signal. Is it in the waiting state in child process as well ?

推荐答案

在Linux线程时下试图留POSIX complient。只有调用线程被复制,而不是其它线程(请注意,例如,在Solaris上,你可以选择你根据链接库什么什么叉子一样)

Threads on linux nowadays tries to stay posix complient. Only the calling thread is replicated, not other threads (note that e.g. on solaris you can chose what fork does depending on what library you link to)

从<一个href=\"http://www.opengroup.org/onlinepubs/000095399/functions/fork.html\">http://www.opengroup.org/onlinepubs/000095399/functions/fork.html:

一个过程应与创建
  单个线程。如果一个多线程
  进程调用fork(),新工艺
  应包含主叫的翻版
  线程及其整个地址空间,
  可能包括的状态
  互斥体和其他资源。
  因此,为了避免错误,
  子进程可能只执行
  异步信号安全操作,直到
  这种时间的exec函数
  叫做。叉子
  处理程序可以下述方法确定
  在pthread_atfork()函数
  为了保持应用程序
  通过fork不变量()调用。

A process shall be created with a single thread. If a multi-threaded process calls fork(), the new process shall contain a replica of the calling thread and its entire address space, possibly including the states of mutexes and other resources. Consequently, to avoid errors, the child process may only execute async-signal-safe operations until such time as one of the exec functions is called. Fork handlers may be established by means of the pthread_atfork() function in order to maintain application invariants across fork() calls.

这篇关于叉的和现有的主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆