I always hear that you should never use system()
and instead fork/exec
because system() blocks the parent process.
If so, am I doing something wrong by calling waitpid()
, which also blocks the parent process when I do a fork/exec
? Is there a way around calling waitpid
...I always thought it was necessary when doing a fork/exec
.
pid_t pid = fork();
if (pid == -1)
{
// failed to fork
}
else if (pid > 0)
{
int status;
waitpid(pid, &status, 0);
}
else
{
execve(...);
}