-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessinfo_user.c
More file actions
53 lines (50 loc) · 1.73 KB
/
processinfo_user.c
File metadata and controls
53 lines (50 loc) · 1.73 KB
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
#include <stdio.h>
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
char *all_processes = (char *)malloc(4000);
int kill_id;
char *process_id = malloc(150);
char *commandline = (char *)malloc(200);
char *argument = (char *)malloc(10);
if (argc == 1) // if there is no argument
{
printf("\nRight Usage:\n");
printf("\t-all prints some information (process id and its argument/s) about all processes\n");
printf("\t-p takes process id and prints the details of it\n");
printf("\t-k takes process id\n");
}
else if (argc == 2 && strcmp(argv[1], "-all") == 0) // if -all argument is given
{
argument = argv[1];
long int amma = syscall(335, all_processes, process_id, kill_id, commandline, argument);
printf("Process id and the argument list for the processes:\n");
printf("uid\t\tppid\t\tpid\t\tname\t\tstate\n");
char *token = strtok(all_processes, ",");
while (token != NULL)
{
printf(" %s\n", token);
token = strtok(NULL, ",");
}
}
else if (argc == 3 && strcmp(argv[1], "-p") == 0) // if -p argument and process id are given
{
argument = argv[1];
process_id = argv[2];
long int amma = syscall(335, all_processes, process_id, kill_id, commandline, argument);
printf("Argument#[%s]-Process Information: \n", argv[2]);
printf("pid\t\tcommandline\n", process_id, commandline);
printf("%s\t\t%s\n", process_id, commandline);
}
else if (argc == 3 && strcmp(argv[1], "-k") == 0) // if -k argument and process id are given
{
argument = argv[1];
kill_id = atoi(argv[2]);
long int amma = syscall(335, all_processes, process_id, kill_id, commandline, argument);
printf("Process %s was killed... ", argv[2]);
}
}