I am building a feature, where I can open and close files in vi
editor. I am using execlp()
system call in C for opening a file in a new terminal window in a new child process. Here is how it looks:
void openFile (char *fileName) {
int pid=fork();
if (pid==0){
execlp("gnome-terminal", "gnome-terminal", "--", "vi", fileName, NULL) ;
}
insert(fileName, pid);
return;
}
So for closing the file, I have the child process Id.
void closeProcess (int pid){
printf("killing %d\n", pid);
kill(pid, SIGKILL);
return;
}
Now the challenge is this process id is not the same as the vi
editor process id. Killing this process is not closing the vi
editor.
Here are some example processes. The process id that I have in pid variable is 25803 but is now dead. To kill vi
editor I need the process id 25815.
How killing vi
process working.
Here is my current program output, which doesn't close vi
editor for that file.