-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverkill.c
61 lines (60 loc) · 1.39 KB
/
overkill.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
53
54
55
56
57
58
59
60
61
#include "headers.h"
#include "overkill.h"
#include "other.h"
int overkill(char *command)
{
error_code=0;
char com[1024][1024];
int word_count = 0;
int char_count = 0;
for (int i = 0; i < strlen(command); i++)
{
if (command[i] != ' ' && command[i] != '\t' && command[i] != '\0')
{
while (command[i] != ' ' && command[i] != '\t' && command[i] != '\0')
{
com[word_count][char_count] = command[i];
i++;
char_count++;
}
com[word_count][char_count] = '\0';
word_count++;
char_count = 0;
}
}
if (word_count != 1)
{
error_code=1;
fprintf(stderr, "overkill: Invalid number of arguments\n");
return -1;
}
else
{
struct bg_prc *a = malloc(sizeof(struct bg_prc));
a = initial;
if (initial->size == 0)
{
return 1;
}
else
{
while (1)
{
if(kill(a->pid, SIGKILL)!=0)
{
error_code=1;
}
signal(SIGCHLD, func);
if(a->next==NULL)
{
break;
}
else
{
a=a->next;
}
}
return 1;
}
}
}