New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add subprocess-signal. #961

wants to merge 2 commits into
base: master


None yet
2 participants
Copy link

kach commented Jun 12, 2015

This PR creates a new primitive, subprocess-signal, which allows users to send arbitrary POSIX signals to a subprocess. There are many, many use-cases for this, such as communicating with obscure processes that accept SIGUSR*, suspending and resuming process with SIGSTOP and SIGCONT, and even implementing subprocess-kill within Racket rather than as a separate C primitive.

A simple test case and example is:

#lang racket
(define-values (p stdout stdin stderr) (subprocess #f #f #f "/usr/bin/python" ""))
(display (read-line stdout))
(subprocess-signal p 'SIGTERM) ; or any other signal name like SIGUSR1
(display (read-line stdout))

In file, we have:

import signal
import sys
import time

print "Bananas!"

def beep(num, stack):
    print "Got signal:", num

signal.signal(signal.SIGHUP, beep)
signal.signal(signal.SIGINT, beep)
signal.signal(signal.SIGQUIT, beep)
signal.signal(signal.SIGILL, beep)
signal.signal(signal.SIGTRAP, beep)
signal.signal(signal.SIGABRT, beep)
signal.signal(signal.SIGEMT, beep)
signal.signal(signal.SIGFPE, beep)
#signal.signal(signal.SIGKILL, beep)
signal.signal(signal.SIGBUS, beep)
signal.signal(signal.SIGSEGV, beep)
signal.signal(signal.SIGSYS, beep)
signal.signal(signal.SIGPIPE, beep)
signal.signal(signal.SIGALRM, beep)
signal.signal(signal.SIGTERM, beep)
signal.signal(signal.SIGURG, beep)
#signal.signal(signal.SIGSTOP, beep)
signal.signal(signal.SIGTSTP, beep)
#signal.signal(signal.SIGCONT, beep)
signal.signal(signal.SIGCHLD, beep)
signal.signal(signal.SIGTTIN, beep)
signal.signal(signal.SIGTTOU, beep)
signal.signal(signal.SIGIO, beep)
signal.signal(signal.SIGXCPU, beep)
signal.signal(signal.SIGXFSZ, beep)
signal.signal(signal.SIGVTALRM, beep)
signal.signal(signal.SIGPROF, beep)
signal.signal(signal.SIGWINCH, beep)
signal.signal(signal.SIGINFO, beep)
signal.signal(signal.SIGUSR1, beep)
signal.signal(signal.SIGUSR2, beep)

while True:

This feature is UNIX-only, though a small subset of the signals have Windows equivalents which I can try to implement later.


This comment has been minimized.

Copy link

kach commented Jun 12, 2015

Note: The reason it fails on Travis/Linux is because Linux defines a different set of signal constants than OSX does. We should use a smaller set of signals which is guaranteed to be defined everywhere.

EDIT: the offending signals are SIGINFO and SIGEMT


This comment has been minimized.

Copy link

mflatt commented Jun 20, 2015

Thanks for the patch! I like the idea of subprocess-signal, but I'd like to look more into how the set of supported signals can be generally portable and complete (where the latter might mean accepting numerical values as well as symbols). I can't get to it just now, but I'll hopefully be able to follow up soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment