Mystery pthread task with fork ()

I have a program that:

  • has a main thread (1) that starts the server thread (2) and another (4).
  • server thread (2) does accept () and then creates a new thread (3) to handle the connection.

At some point, thread (4) executes fork / exec to run another program that needs to connect to the socket that is listening on thread (2). Sometimes it fails or takes an unreasonably long time, and it is extremely difficult to diagnose. If I build the system, it seems that fork / exec was working, a reception has occurred, a new thread (4) has been created .. but nothing happens in this thread (using strace -ff, the file for the corresponding pid is empty).

Any ideas?

+3
source share
5 answers

I came to the conclusion that this phenomenon is probably:

http://kerneltrap.org/mailarchive/linux-kernel/2008/8/15/2950234/thread

since the error is difficult to run on our development systems, but is usually reported by users working on large shared computers; also a forked application runs the JVM, which itself allocates many threads. The problem is also related to a bootable machine and heavy memory usage (we have a machine with 128 GB of RAM, and processes can have a size of 10-100 GB).

O'Reilly pthreads, pthread_atfork(), " ", , . . , .

+2

. , accept(), .

+1

, - . , .

BTW - http://lists.samba.org/archive/linux/2002-February/002171.html , pthread exec .

fork exec? .

0

. glibc/libstd++ . , forking, , , . . . man pthread_atfork.

0

, , , fork() . , fork() , ...

The following are the rules from the Mini-Guide on fork () and Pthreads :

1- YOU DO NOT WANT TO DO IT.

2- If you need fork (), then: if possible, fork () is all yours before the start of any threads.

Edit: try, fork () does not duplicate threads.

-2
source

Source: https://habr.com/ru/post/1717448/


All Articles