i’m working with a multi-threaded program (using pthreads) that currently create a background thread (PTHREAD_DETACHED) and then invokes pthread_exit(0). My problem is that the process is then listed as ‘defunct’ and curiously do not seems to ‘really exists’ in /proc (which defeats my debugging strategies)
I would like the following requirements to be met:
- the program should run function A in a loop and function B once
- given the PID of the program /proc/$pid/exe, /proc/$pid/maps and /proc/$pid/fd must be accessible (when the process is defunct, they are all empty or invalid links)
- it must be possible to suspend/interrupt the program with CTRL+C and CTRL+Z as usual
edit: I hesitate changing the program’s interface for having A in the ‘main’ thread and B in a spawned thread (they are currently in the other way). Would it solve the problem ?
You can either suspend the execution of the main process waiting for a signal, or don’t detach the thread (using the default PHTREAD_CRATE_JOINABLE) waiting for its termination with a
pthread_join().