There is basic job control like suspend, resume, interrupt, and background implemented by most modern shells.
How can I make a shell sensitive to ^Z, fg, ^C, and bg (as they appear in bash), in Python? Or what should I be reading?
There is basic job control like suspend, resume, interrupt, and background implemented by most modern shells.
How can I make a shell sensitive to ^Z, fg, ^C, and bg (as they appear in bash), in Python? Or what should I be reading?
No need to do anything :
python -c 'import time; time.sleep(600)'
You can test all your keyboard combos ;)
You can capture signals sent to your program using signal
module. For instance ^Z
means SIGTSTP
in Unix like systems.
import signal
jobs = []
def handler(signum, frame):
jobs.append(frame)
signal.signal(signal.SIGTSTP, handler)
Now when you type Ctrl+Z handler
will be called and print "catch". You can capture ^C
using signal.SIGINT
.