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:
So for closing the file, I have the child process Id.
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 the processes. 25803
is the process id that I have in pid variable which is a dead process. To kill vi
editor I need 25815
process id.
How killing vi
process working.
Here is my current program output, which doesn't close vi
editor for that file.
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main() {
int pid = 20989; // That PID has a PGID of 20988
int pgid = getpgid(pid);
printf("pgid = %d\n", pgid);
}
Alternatively you can use this ps
command:
ps xao pid,ppid,pgid,sid,command will show
The KILL signal instructs Linux to end the job immediately. Any open files are closed in place. There is no clean up of user land state by the application.
Alternatively, sending SIGTERM instructs the application to end. Permitting the application to close all files, save their state, and prepare to end.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.