I have two Python scripts foo.py
and bar.py
, foo.py
will call bar.py
via os.system()
.
#foo.py
import os
print os.getpid()
os.system("python dir/bar.py")
#bar.py
import time
time.sleep(10)
print "over"
Say the pid of foo.py
is 123, if the program terminate normally, it'll print
123
over
If I type kill 123
while it's running, I'll get the following output
123
Terminated
over
If I press Ctrl-C while it's running, I'll get something like
123
^CTraceback (most recent call last):
File "dir/bar.py", line 4, in <module>
time.sleep(10)
KeyboardInterrupt
But if I type kill -SIGINT 123
while it's running, it seems the program will just ignore the signal and exit normally.
123
over
It seems to me that,
if I type kill 123
, the sub-process will not be affected.
if I type Ctrl-C, both processes will be terminated.
if I type kill -SIGINT 123
while the sub-process is running, the signal will be ignored.
Can someone please explain to me how it works?
Isn't Ctrl-C and kill -SIGINT
supposed to be equivalent?
If I type kill 123
is it guaranteed that the sub-process will not be affected (if it happens to be running)?
I am on Ubuntu 14.04 by the way. Thanks!