TIP 540: Add -signal Channel Configure Option to POSIX Pipes

Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to tclconference@googlegroups.com
or submit via the online form by Sep 9.
Author:         Donal K. Fellows <donal.k.fellows@manchester.ac.uk>
State:          Draft
Type:           Project
Tcl-Version:    8.7
Vote:           Pending
Created:        03-May-2019
Keywords:       Tcl, Unix, pipeline
Post-History:

Abstract

This TIP adds a write-only option for delivering a signal to the processes in a pipeline it has created.

Rationale

Although Tcl has long had a way for pipelines to be created (via the right incantation to open) and their process IDs retrieved (with pid $pipe), and gained the ability to partially close a bidirectional pipeline with TIP #332, it lacks a mechanism for sending a signal to the pipeline. Binding this capability to the pipeline, rather than making it work for general process IDs, means that user scripts can work at the level of pipelines and not pay too much attention to their components.

This TIP does not provide support for doing the same thing on Windows, where the types of signals (and other related events) are substantially different.

Specification

Pipeline channels shall gain an extra set-only chan configure option, -signal, which may be set to send the indicated signal to all the processes in the pipeline that Tcl knows about (i.e., those returned by pid $pipe). The signal to send may be specified as either a positive number or a case-insensitive signal name (with or without the SIG prefix), with the set of supported signal names being system-specific (but the “well-known” set).

The effect of the signal on the pipeline is out of scope.

Example

This creates a (very silly!) pipeline, lets it run for 5 seconds, kills it with a terminate signal, then reads all the output (if any):

set pipe [open |[list cat /dev/random | grep fish]]
after 5000
chan configure $pipe -signal SIGTERM
# Also legal: -signal 15 or -signal TERM or -signal sigterm
set output [read $pipe]
catch {close $pipe}

Reference Implementation

TODO

Copyright

This document has been placed in the public domain.