Olli Graf
12 months ago
5 changed files with 63 additions and 3 deletions
@ -0,0 +1,19 @@ |
|||||
|
#! /usr/bin/python3 |
||||
|
# encoding:utf-8 |
||||
|
|
||||
|
import signal |
||||
|
import time |
||||
|
|
||||
|
|
||||
|
def handle_alarm(signum, frame): |
||||
|
print(f'Alarm ausgelöst bei {time.ctime()}') |
||||
|
|
||||
|
signal.signal(signal.SIGALRM,handle_alarm) |
||||
|
|
||||
|
signal.alarm(3) |
||||
|
|
||||
|
print(f'aktuelle Zeit Start: {time.ctime()}') |
||||
|
|
||||
|
time.sleep(13) |
||||
|
print(f'aktuelle Zeit Ende: {time.ctime()}') |
||||
|
|
@ -0,0 +1,41 @@ |
|||||
|
#! /usr/bin/python3 |
||||
|
|
||||
|
import time |
||||
|
import signal |
||||
|
import sys |
||||
|
|
||||
|
#Behandlung von SIGINT (CTRL-C) |
||||
|
def handle_sigint(signum, frame) : |
||||
|
print(f'Handling signal {signum} ({signal.Signals(signum).name}).') |
||||
|
|
||||
|
if signum == signal.SIGINT: |
||||
|
print(f'SIGINT wird behandelt. {frame}') |
||||
|
time.sleep(1) |
||||
|
sys.exit(0) |
||||
|
|
||||
|
#Behandlung von SIGTSTP (CTRL-Z) |
||||
|
|
||||
|
def handle_sigtstp(signum,frame): |
||||
|
print(f'Behandle signal {signum} ({signal.Signals(signum).name}).') |
||||
|
|
||||
|
print('Programm in Hintergrund') |
||||
|
|
||||
|
# Behandlung von SiGCONT |
||||
|
def handle_sigcont(signum,frame): |
||||
|
print(f'Behandle signal {signum} ({signal.Signals(signum).name}).') |
||||
|
|
||||
|
print('Programm im Vordergrund') |
||||
|
|
||||
|
if __name__ == '__main__': |
||||
|
# Interrupt Handler registrieren |
||||
|
signal.signal(signal.SIGINT, handle_sigint) |
||||
|
signal.signal(signal.SIGTSTP, handle_sigtstp) |
||||
|
signal.signal(signal.SIGCONT, handle_sigcont) |
||||
|
|
||||
|
for i in range(0,10000000): |
||||
|
print(f'Schleife: {i}') |
||||
|
time.sleep(0.5) |
||||
|
print('Schleifenende') |
||||
|
|
||||
|
|
||||
|
|
Loading…
Reference in new issue