-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_func.c
68 lines (63 loc) · 1.41 KB
/
handler_func.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
#include "header.h"
// creating array containing name of signals corresponding to their number
/*void createsignal()
{
int sig,i,len;
char *str;
char **temp;
char c;
for (sig = 1; sig < NSIG; sig++)
{
printf("entered\n");
str = strdup(sys_siglist[sig]);
// temp[sig]=str;
// signum_to_name[sig]=str;
len=strlen(str);
for (i = 0; i<len; i++)
{
c=str[i];
// printf("c : %c\n",c);
str[i]=toupper(c);
}
printf("yes\n");
printf("%s\n",str);
// signum_to_name[sig]=str;
// printf("copied\n");
// signum_to_name[sig]='\0';
// strcpy(signum_to_name[sig],str);
}
} */
void childhandler(int signal)
{
int status,i;
pid_t pid;
if (signal==SIGCHLD)
{// sleep(0);
while((pid=waitpid(-1, &status,WNOHANG))> 0)
{ //printf("\n");
for(i=0;i<back_index;i++)
{
if((back_job[i].pro_id)==pid)
{
back_job[i].back_active=0;
// printf("zeroed: %d %d\n",back_job[i].pro_id,back_job[i].back_active);
break;
}
}
if(WIFEXITED(status))
{
printf("\n%s with pid %d terminated with exit status: ",back_job[i].processname,pid);
printf("%d\n",WEXITSTATUS(status));
}
else
{
if(WIFSIGNALED(status))
{
if(over_mark!=1)
printf("\n%s with pid %d exited due to the signal no. %d\n",back_job[i].processname ,pid,WTERMSIG(status));
}
}
printprompt();
}
}
}