completes the processes md and adds the exercises
This commit is contained in:
parent
3bb4a65b6d
commit
e227b234c0
|
@ -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))
|
|
@ -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
|
|
@ -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)
|
Loading…
Reference in New Issue