-
Notifications
You must be signed in to change notification settings - Fork 0
/
sig.c
40 lines (39 loc) · 850 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
#include "headers.h"
#include "sig.h"
void sig_implementation(int parts, char **args)
{
if (parts > 2)
{
printf("sig: incorrect number of arguments \n");
return;
}
int procid = atoi(args[0]);
if (procid < 0)
{
printf("sig: expected a positive process id \n");
return;
}
pid_t pid = get_pid_from_id(procid, head);
if (pid == -1)
{
printf("sig: no such process exists \n");
return;
}
int signum = atoi(args[1]);
if (signum < 0)
{
printf("sig: expected a positive signal id \n");
return;
}
int r1 = kill(pid, signum);
if (r1 < 0)
{
printf("sig: not able to send signal \n");
return;
}
else
{
printf("signal sent to process with pid [%d] successfully \n", pid);
}
return;
}