-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignal_handle.c
More file actions
39 lines (34 loc) · 852 Bytes
/
signal_handle.c
File metadata and controls
39 lines (34 loc) · 852 Bytes
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
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#include "main.h"
//for ctrl+C
void sighandler_c(int signum) {
if (current_pid != atoi(shell_pid) && current_pid != 0)
{
for(int i=0;i<p_len;i++)
if(current_pid == PROC[i].pid)
{
if (PROC[i].stat == -1)
kill(current_pid,SIGKILL);
return ;
}
kill(current_pid,SIGKILL);
current_pid = current_ppid = 0;
}
}
//for Ctrl+Z
void sighandler_z(int signum) {
if(current_pid != atoi(shell_pid) && current_pid != 0)
{
store_pid(current_pid,current_ppid);
kill(current_pid,SIGTSTP);
current_pid = current_ppid = 0;
}
}
void sighandler_ch(int signum){
print_background();
}