int status=0;
int PID = fork();
if(PID == 0)
{
char *path = strcat(pathToken,strcat("/",command));
printf("path: %s\n",path);
execl(path,command,"-l",NULL);
}
else if(PID>0)
{
printf("pid: %d. ",PID);
printf("I'm parent process\n");
wait(&status);
}
Output:
pid: 20027. I'm parent process
Why it doesn’t enter if(PID==0)?
You are trying to modify a string literal in:
which leads to undefined behavior.
The declaration for strcat is:
And it appends a copy of the source string to the destination string.