forked from Jawoos/SystemPrograming_Team9
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dokill.c
116 lines (106 loc) · 2.3 KB
/
dokill.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <ncurses.h>
#include "rd.h"
#define BLANK "\t\t\t\t\t\t\t\t\t\t "
void do_kill(psinfo* ary, int size){
int total = 0;
if(size == 1)
{
printw("There is nothing available process to kill");
refresh();
}
for(int i = 0; i < size; i++){
//printf("print check of pid(%d) : %d and my pid is %d\n", ary[i].pid, ary[i].checkTokill, getpid());
if(ary[i].checkTokill == 0){
//printf("processor (%d) will be killed\n", ary[i].pid);
total++;
kill(ary[i].pid, SIGINT);
}
}
printw("total kill: %d", total);
refresh();
sleep(2);
}
void do_must_kill(psinfo* ary, int size){
int total = 0;
if(size == 1)
{
printw("There is nothing available process to kill");
refresh();
}
for(int i = 0; i < size; i++){
//printf("print check of pid(%d) : %d and my pid is %d ppid is %d\n", ary[i].pid, ary[i].checkTokill, getpid(), getppid());
if(ary[i].checkTokill == 0){
//printf("processor (%d) will be killed\n", ary[i].pid);
// sleep(60);
total++;
kill(ary[i].pid, SIGKILL);
}
}
printw("total kill: %d", total);
refresh();
sleep(2);
}
void get_pid(psinfo* ary1, int size1, psinfo* ary2, int size2, int lines)
{
signal(SIGALRM, SIG_IGN);
int input;
int i;
sleep(1);
while(input != -1)
{
move(lines - 2, 0);
printw("\t\t\t\t\t");
refresh();
move(lines - 2, 0);
printw("what is want to kill pid?(exit : -1)");
scanw("%d", &input);
refresh();
move(lines -1, 0);
sleep(1);
addstr(BLANK);
refresh();
for(i = 0; i < size1; i++)
{
if(ary1[i].pid == input)
{
move(lines -1, 0);
printw("pid(%d) is exception", ary1[i].pid);
refresh();
ary1[i].checkTokill = 1;
}
}
for(i = 0; i < size2; i++)
{
if(ary2[i].pid == input)
{
move(lines -1, 0);
printw("pid(%d) is exception", ary2[i].pid);
refresh();
ary2[i].checkTokill = 1;
}
}
}
}
void store_CK(psinfo* ary, int size, int* CK, int* cksize) //store checkTokill's pid
{
for(int i = 0; i < size; i++)
{
if(ary[i].checkTokill == 1)
CK[(*cksize)++] = ary[i].pid;
}
}
void set_CK(psinfo* ary, int size, int* CK, int cksize) //set checkTokill values
{
for(int i = 0; i < size; i++)
{
for(int j = 0; j < cksize; j++)
{
if(CK[j] == ary[i].pid)
ary[i].checkTokill = 1;
}
}
}