2

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?

nneonneo
  • 171,345
  • 36
  • 312
  • 383
Christos Hayward
  • 5,777
  • 17
  • 58
  • 113

2 Answers2

0

No need to do anything :

python -c 'import time; time.sleep(600)'

You can test all your keyboard combos ;)

Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
0

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.

Pedro Lacerda
  • 1,098
  • 9
  • 23