completes the processes md and adds the exercises

This commit is contained in:
waldek 2021-07-05 15:48:42 +02:00
parent 3bb4a65b6d
commit e227b234c0
3 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,13 @@
import time
import os
start_ts = time.time()
loops = 0
while True:
time.sleep(1)
loops += 1
tick_ts = time.time()
delta = int(tick_ts - start_ts)
pid = os.getpid()
print("I'm {} and I've been running for {} seconds and did {} loops".format(pid, delta, loops))

View File

@ -0,0 +1,23 @@
import time
import os
import random
start_ts = time.time()
loops = 0
while True:
time.sleep(1)
loops += 1
tick_ts = time.time()
delta = int(tick_ts - start_ts)
pid = os.getpid()
print("I'm {} and I've been running for {} seconds and did {} loops".format(pid, delta, loops))
chance = random.randint(0, 20)
if chance == 5:
response = input("I need some input...")
if len(response) == 0:
exit(0)
else:
print("thanks for the response, I'll reset my counter and continue now...")
start_ts = time.time()
loops = 0

View File

@ -0,0 +1,18 @@
import time
import os
import signal
def alarm_handler(signum, frame):
print("I'm an alarm hear me ring! (my ID is {})".format(signum))
def main():
print("I'm {}".format(os.getpid()))
while True:
time.sleep(1)
if __name__ == "__main__":
signal.signal(signal.SIGALRM, alarm_handler)
try:
main()
except Exception as e:
print(e)