Here is an example, ignorning the error checking:
int main()
{
pid_t pid = fork();
if(0 == pid)
{
for(int i = 0; i < 5; ++i)
{
char* const args[] = { "/bin/ls", nullptr };
execve("/bin/ls", args, nullptr);
}
}
else if(pid > 0)
{
wait(nullptr);
}
}
If exec() after fork(), as far as I know, the linux will not copy but cover original system.
If I want to keep running execve() in for() loop like this, what should I do ?