-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
31 lines (24 loc) · 1.17 KB
/
server.py
File metadata and controls
31 lines (24 loc) · 1.17 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
import os
import signal
import time
info=""
def sigusr1_handler(signum, frame):
print("Server received SIGUSR1 signal")
print(" -- Adding a 0 to the array")
global info
info += "0"
print("Array so far, ", info)
def sigusr2_handler(signum, frame):
print("Server received SIGUSR2 signal")
print(" -- Adding a 1 to the array")
global info
info += "1"
print("Array so far, ", info)
# Register signal handlers
signal.signal(signal.SIGUSR1, sigusr1_handler)
signal.signal(signal.SIGUSR2, sigusr2_handler)
# Print the server's PID
print(f"Server PID: {os.getpid()}")
print("Server is running...")
while True:
time.sleep(1)