Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test] Preparing for job control and signal changes
- demo: How to handle SIGINT in Python - test/stateful: Repro of issue #1005 - But I want to fix the issue where Ctrl-Z is ignored first ... - Rename devtools/sigparse.sh -> test/signal-state.sh - Start test/group-session.sh
- Loading branch information
Andy C
committed
Feb 5, 2022
1 parent
281c220
commit b7ed2ce
Showing
6 changed files
with
93 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env python2 | ||
""" | ||
py_signals.py | ||
""" | ||
from __future__ import print_function | ||
|
||
import signal | ||
import sys | ||
import time | ||
|
||
|
||
|
||
g_sigint = False | ||
|
||
def SigInt(x, y): | ||
print('SIGINT') | ||
global g_sigint | ||
g_sigint = True | ||
|
||
|
||
def main(argv): | ||
|
||
# This suppresses KeyboardInterrupt. You can still do Ctrl-\ or check a flag | ||
# and throw your own exception. | ||
signal.signal(signal.SIGINT, SigInt) | ||
|
||
while True: | ||
print('----') | ||
time.sleep(0.5) | ||
if g_sigint: | ||
raise Exception('interrupted') | ||
|
||
|
||
if __name__ == '__main__': | ||
try: | ||
main(sys.argv) | ||
except RuntimeError as e: | ||
print('FATAL: %s' % e, file=sys.stderr) | ||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Test kernel state: the process group and session leader. | ||
# | ||
# Usage: | ||
# ./group-session.sh <function name> | ||
|
||
set -o nounset | ||
set -o pipefail | ||
set -o errexit | ||
|
||
show() { | ||
# by deafult, it shows processes that use the same terminal | ||
ps -o pid,ppid,pgid,sid,tname,comm | ||
} | ||
|
||
"$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters