Double fork using vfork

HI
I am writing the part of the server that should send some other child processes.
Since I want to wait for some processes and send others without waiting for completion, I use a double fork for the second type of processes (thus avoiding zombie processes).
The problem is that a lot of memory is stored on my server, so forking takes a lot of time (even the copy-to-write fork used in Linux, which only copies paging tables)
I want to replace fork () with vfork (), and this is easy for the second fork (since it only calls execve () on the child), but I could not find a way to replace the first.
Does anyone know how I can do this?
Thank!

The server is Linux (RH5U4) written in C ++.

+3
source share
5 answers

Why not just get the new exec'd process to make another fork? Thus, only a small simple process will be copied by page tables?

EDIT:

Of course, the parent will have to do a short wait () to clear the zombies of this, but the grandson process could work as long as he wanted.

+2
source

vfork()can only be used for fork, and then calls execor exit. It also vfork()blocks the parent process until the child calls _exitor exec, which almost certainly does not correspond to the behavior.

, vfork() - , , . , , , . , , , _exit exec, .

+1

, , SIGCHLD . , , ( , ), - . - , , , ( ) , .

+1

. SIGCHLD, errno, wait, errno.

+1

I believe that you can use the answer to another question that I asked for the same reason. You can vfork()+ exec()execute an executable file that opens again. See setuid () before calling execv () in vfork () / clone ()

+1
source

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


All Articles