I am trying to accomplish a simple task... But I couldn't make it to work properly.
The code below is an attempt to "fork + execute a new process" but it is not working as I expected because when the child executes the process, it behaves differently when it is called by the parent.
Can you say what am I doing wrong?
Code:
#include <unistd.h>
long int main(long argc, char** argv, char** envp)
{
char* fpath = "/home/ignorant/Desktop/test2";
char* agv[] = {fpath, 0};
int frk = fork();
if (frk != 0)
{
// parent!
if (frk > 0)
{
// successful! Executed program behaves OK from here...
//execve(fpath, agv, NULL);
return 0;
}
else
{
// failed!
return 3;
}
}
else
{
// child! Executed program behaves differently from here...
execve(fpath, agv, NULL);
return 3;
}
}
Thank you!