Skip to content

Instantly share code, notes, and snippets.

@podhmo
Created September 4, 2015 08:59
Show Gist options
  • Save podhmo/68231f93ef43323f358b to your computer and use it in GitHub Desktop.
Save podhmo/68231f93ef43323f358b to your computer and use it in GitHub Desktop.
# -*- coding:utf-8 -*-
import time
import signal
import sys
def handler(signal, frame):
sys.stdin = sys.stdout = open("/tmp/link", "r+")
signal.signal(signal.SIGTERM, handler)
i = 0
while True:
i += 1
print(i)
time.sleep(1)
"""
we have two terminal
- terminal0
- terminal1
terminal0> $ python calc.py&
[1] 57810
terminal0> $ jobs -p
57810
1
2
3
4
5
6
7
...
100
101
terminal1> $ tty
/dev/ttys012
terminal1> $ ln -s `tty` /tmp/link
terminal1> $ kill -s TERM 57810
102
103
104
...
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment