简体   繁体   中英

how to handle fork() error in multi-process application with no exec*()

I'm creating processes in loop with fork() function. The new processes do not call any function in the exec*() family; they just run their code and then exit using exit() . They can't fail.

But I don't know what to do if fork() fails and I have already created some new processes. Do I have to use return or exit() ? Do I have to use killpg() to kill created processes? If fork() fails, I want to clean everything and exit program from main process. Can someone give me a hint how to do this?

Calling killpg(getpgrp(), SIGKILL) followed by exit(...) or return ... should do the job.

For reference: killpg() , getpgrp()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM