You only call execv()
in the child process. The exec()
family functions never return if it runs successfully. See evec(3):
The
exec()
functions only return if an error has occurred. The return value is-1
, anderrno
is set to indicate the error.
You printed the value of i
in the parent process, it never changed in the parent process.
To get the exit status from the child process, you can make use of wait()
or waitpid()
:
else {
int waitstatus;
wait(&waitstatus);
i = WEXITSTATUS(waitstatus);
}