-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day 9.C
30 lines (26 loc) · 880 Bytes
/
Day 9.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
#include <ncurses.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
if (argc < 3) {
printf("Usage: manager [open|close] [app name]\n");
return 1;
}
char *command;
if (strcmp(argv[1], "open") == 0) {
command = malloc(strlen("open -a ") + strlen(argv[2]) + 1);
strcpy(command, "open -a ");
strcat(command, argv[2]);
} else if (strcmp(argv[1], "close") == 0) {
command = malloc(strlen("kill $(ps -ef | grep ") + strlen(argv[2]) + strlen(" | grep -v grep | awk '{print $2}')") + 1);
strcpy(command, "kill $(ps -ef | grep ");
strcat(command, argv[2]);
strcat(command, " | grep -v grep | awk '{print $2}')");
} else {
printf("Usage: manager [open|close] [app name]\n");
return 1;
}
system(command);
free(command);
return 0;
}