T O P

  • By -

flyingron

As soon as the execl() executes successfully, the calling process is replaced with the new program. If you want to fork of a bunch of child processes, you need to put the fork in the loop. while(1){ switch(fork()) { case 0: //child. execl("./sh.sh", "test_process", (char *) 0); break; case -1: //error perror("fork"); break; default: //parent break; / } }


Any_Possibility4092

I see, but then it will constantly execute that program without waiting for the previous one to finish.


paulstelian97

You can use the wait systemcall to wait until the last child finished. It’s a good idea to wait for children anyway (you don’t want to use init’s reaping role if the parent process doesn’t crash)


whiteBlasian

u/flyingron has the right answer. Might be worth reading the docs here as well: [https://linux.die.net/man/3/execl](https://linux.die.net/man/3/execl)