-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13a.c
More file actions
47 lines (39 loc) · 1.35 KB
/
13a.c
File metadata and controls
47 lines (39 loc) · 1.35 KB
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
/*
============================================================================
Name : 13a
Author : Piyush Singh
Description : Write two programs: first program is waiting to catch SIGSTOP signal, the second program
will send the signal (using kill system call). Find out whether the first program is able to catch
the signal or not.
Date: 19th Sep, 2025.
============================================================================
*/
// Program 1: Receiver — tries to catch SIGSTOP (but can't)
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
// This handler will never be called for SIGSTOP
void stop_handler(int sig)
{
printf("🛑 Received SIGSTOP — but this message will never appear.\n");
}
int main()
{
// Attempt to catch SIGSTOP (this won't work)
signal(SIGSTOP, stop_handler);
// Print our PID so the sender knows who to target
pid_t my_pid = getpid();
printf("📍 Receiver running. My PID is %d\n", my_pid);
printf("⌛ Waiting... Try sending SIGSTOP from another terminal.\n");
// Keep the process alive so it can be stopped
while (1)
sleep(1);
return 0;
}
/*
Output :
╰─ ./13a ─╯
📍 Receiver running. My PID is 21084
⌛ Waiting... Try sending SIGSTOP from another terminal.
[2] + 21084 suspended (signal) ./13a
*/