-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsig.c
52 lines (52 loc) · 991 Bytes
/
sig.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdbool.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "sig.h"
int check_v(int argc)
{
if (argc > 3)
{
printf("TOO MANY ARGUMENTS \n");
return -1;
}
if (argc < 3)
{
printf("TOO FEW ARGUMENTS \n");
return -1;
}
return 0;
}
int check_pid(int pid)
{
if (pid < 0)
{
perror("Invalid PID");
return -1;
}
return 0;
}
void sig(int argc, int pid, int signal_index)
{
int check_if_v = check_v(argc);
if (check_if_v == -1)
{
return;
}
int check_valid_pid = check_pid(pid);
if (check_valid_pid == -1)
{
return;
}
// you call kill with corresponding sig_num as in third argument you process getskilled with given command
int sig_term= kill(pid,signal_index);
if (sig_term==-1)
{
perror("SIG ERROR");
return;
}
}