-
Notifications
You must be signed in to change notification settings - Fork 0
/
mains.c
executable file
·67 lines (53 loc) · 1.41 KB
/
mains.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
#include "headers.h"
#include "functions.c"
void sigi(int sig)
{
printf("ctrlc pressed\n");
return;
}
int proc[1000];
char *procname[1000];
void handler(int sig)
{
int status;
pid_t ver=waitpid(-1,&status,WNOHANG);
if(ver>0)
{
if(!WIFEXITED(status))
{for(int i=0;i<1000;i++)
{if(proc[i]==ver)
{
printf("\nABNORMAL:process with name %s and pid %d exited abnormally with status:%d\n",procname[i],ver,WEXITSTATUS(status));
proc[i]=-1;
procname[i]=NULL;
}
}
}
}
for(int i=0;i<1000;i++)
{ if(proc[i]>0)
{if(kill(proc[i],0)==-1)
{printf("\nNORMAL EXIT: process with name %s and pid %d exited normally\n",procname[i],proc[i]);
procname[i]=NULL;
proc[i]=-1;}
}
}
}
int main()
{
home=getcwd(home,1000);
char hist[22][1024];
int a=0;
int fd;
int hno;
for(int i=0;i<1000;i++){proc[i]=-1;}
int sze=0;
while(1)
{
signal(SIGINT,sigi);
signal(SIGCHLD,handler);
prompt(a,&fd,&hno,hist,proc,&sze,procname);
a++;
}
return 0;
}