3 ms·
The suggestions here aren't really great. What you should do is already written in the fork(2) manpage https://man7.org/linux/man-pages/man2/fork.2.html https:/
by tuxoko 4y ago
The suggestions here aren't really great. What you should do is already written in the fork(2) manpage https://man7.org/linux/man-pages/man2/fork.2.html https://man7.org/linux/man-pages/man2/fork.2.html
"After a fork() in a multithreaded program, the child can safely call only async-signal-safe functions (see signal-safety(7)) until such time as it calls execve(2)."
So just use only async-singal-safe function
https://man7.org/linux/man-pages/man7/signal-safety.7.html https://man7.org/linux/man-pages/man7/signal-safety.7.html
I don't know why so many people still hit this issue when it already told you what you can do and not do in the document. I've done this sort of things without any issue.
- the_mitsuhiko 4y agoBecause in practice it’s almost impossible to know if you are single threaded still. Plenty of system libraries have background threads.
- emmelaich 4y agoNot to disbelieve you but which ones?
- astrange 4y agoThere are many languages where it's difficult to impossible to be async-signal-safe because you can't avoid memory allocations.