-
Notifications
You must be signed in to change notification settings - Fork 1
/
signals.c
45 lines (43 loc) · 974 Bytes
/
signals.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
#include "headers.h"
void ctrl_c(int sig)
{
pid_t p = getpid();
if(p < 0)
{
perror("Error");
strcpy(emoji,":'(");
}
else if (p != SHELL_ID)
return;
if (p == SHELL_ID && f_current.pid == -1)
{
printf("\n");
prompt();
fflush(stdout);
}
if (f_current.pid != -1)
kill(f_current.pid, SIGINT);
signal(SIGINT, ctrl_c);
}
void stphandler(int sig_num)
{
pid_t p = getpid();
if (p != SHELL_ID)
return;
if (f_current.pid != -1)
{
kill(SIGTTIN, f_current.pid);
signal(SIGTSTP, stphandler);
bg_jobs[num_job].pid = f_current.pid;
strcpy(bg_jobs[num_job].name, f_current.name);
num_job++;
strcpy(emoji,":'(");
printf(DFLT "%s with pid %d is suspended.\n", f_current.name, f_current.pid);
return;
}
signal(SIGTSTP, stphandler);
printf("\n");
prompt();
fflush(stdout);
return;
}