What is C Programming Caution while using execlp function?
programming caution while using execl function series. execlp function series most of the time are used with fork() system call;
If the requirement is there to kill the process started by execl function, then one caution need to take care, as execl functions will replace complete child process image with the new process image, This means new process started is having new pid and not as same as child pid.
In order to kill the process we need to call getpid function in calling function and store this pid in temp file and while killing this new process use
kill(pid) system call.
Example usage assuming in pid is stored in /var/childpid.
programming caution while using execl function series. execlp function series most of the time are used with fork() system call;
If the requirement is there to kill the process started by execl function, then one caution need to take care, as execl functions will replace complete child process image with the new process image, This means new process started is having new pid and not as same as child pid.
In order to kill the process we need to call getpid function in calling function and store this pid in temp file and while killing this new process use
kill(pid) system call.
Example usage assuming in pid is stored in /var/childpid.
fptr = fopen("/var/childpid","r");
if(fptr != NULL)
fgets(child_pid,10,fptr);
else
printf("Can't open childpid file");
close(fptr);
child_pid[strlen(child_pid)-1] = '\0';
sprintf(cmd,"kill %s >/var/done",child_pid);
system(cmd);
Comments