-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignals.c
More file actions
53 lines (51 loc) · 1020 Bytes
/
signals.c
File metadata and controls
53 lines (51 loc) · 1020 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "headers.h"
void ctrlc_handle(int sig)
{
int fg_present;
if (fg_present != 0)
{
if (kill(fg_present, SIGKILL) != 0)
{
}
}
}
void seg_handle(int sig)
{
take_input();
}
void ctrlD_handle(int sig)
{
if (fg_present != 0)
{
if (kill(fg_present, SIGKILL) != 0)
{
}
}
}
void ctrlz_handle(int seg)
{
int fg_present;
if (fg_present != 0)
{
printf("Sending process to background");
if (kill(fg_present, SIGSTOP) != 0)
{
}
}
}
void send_signal(char **command, int bg, int cmd_len, int *pipe_fd, int *pipe_fd2, int active_pipe)
{
pid_t pid = atoi(command[1]);
int signalNumber = atoi(command[2]) % 32;
if (kill(pid, 0) == -1)
{
perror("No such process found");
exit(1);
}
if (kill(pid, signalNumber) == -1)
{
perror("Failed to send signal");
exit(1);
}
printf("Sent signal %d to process with PID %d\n", signalNumber, pid);
}