Can anyone help me with the Kill command in C please?!!!
This code is supposed to list the signals mentioned in the code if I put -l as an argument - but whats happening is is that its displaying the process ID - whats am I doing wrong here?!!! plus when I provide a signal name as an argument alongside with the PID - it doesn't work!! Your help would be appreciated!
include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
int main (int argc, char *argv[])
{
int pid;
int sig;
printf ("In process: %d\n", getpid () );
if (argc == 3){
sig = atoi(argv[1]);
pid = atoi(argv[2]);
kill (pid, sig);
}
if (argc == 2){
pid = atoi(argv[1]);
}
///this is where the problem lies i Think!
if (argc == 2 && argv[2] == '-l'){
printf("SIGHUP, 1\n");
printf("SIGTERM, 15\n");
printf("SIGKILL, 9\n");
}
if(argv[1] == NULL){
printf( "Here1\n");
kill(pid, SIGTERM);
printf("Killed.\n");
system("ps");
return(0);
}
else{
if((sig == SIGTERM) || (sig == 15)){
kill(pid, SIGTERM);
return(0);
}
else{
if((sig == SIGHUP) || (sig == 1)){
kill(pid, SIGHUP);
printf("Killed.\n");
system("ps");
return(0);
}
else{
if((sig == SIGKILL) || (sig == 9)){
kill(pid, SIGKILL);
}
}
}
}
}