Hi folks,
I am trying to write a C program to kill running processing by their process ids.Although,i have been able to get pids,but i cant seem to kill them.Basically,i programmed in perl and python not in C.So,kindly be gentle
Code:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <error.h>
#include <signal.h>
#include <unistd.h>
#include <syslog.h>
int main()
{
FILE *getPIDS;
char line[130];
pid_t killpid;
// setuid to that of root//
pid_t mypid = getpid();
pid_t myppid = getppid();
getPIDS = popen("pidof -x yes","r");
while (fgets(line,sizeof line,getPIDS)) {
printf("KILL PID: %s",line);
kill(line,SIGKILL);
}
}
Output:
Code:
# ./killpids
KILL PID: 11251 11250