-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
61 lines (52 loc) · 983 Bytes
/
main.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 <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>
#include <signal.h>
#include "help.h"
#include "strutils.h"
#include "proc.h"
void proclist()
{
procdir_t procd;
openpdir (&procd);
while (procdnxt (&procd))
{
proc_t proc;
procread (&proc, procd.curpid);
printf ("[%s]: %s - %s\n", proc.pid, proc.name, proc.memsize);
}
}
void prockill(pid_t pid)
{
int exitcode = kill(pid, SIGKILL);
if (exitcode < 0) // error
{
perror("Error on killing the process");
exit(1);
}
printf("Success");
exit(0);
}
int main(const int argc, const char *argv[])
{
if (argc >= 2)
{
if (! strcmp(argv[1], "-h"))
{
print_help();
}
else if (! strcmp(argv[1], "-k"))
{
if (argc < 3)
{
fprintf(stderr, "kill operation (-k) requires a PID as argument");
exit(1);
}
pid_t pid = strtol(argv[2], NULL, 10);
prockill(pid);
}
}
proclist();
return 0;
}