Learn R Programming

subprocess (version 0.8.3)

signals: Sending signals to the child process.

Description

Sending signals to the child process.

Operating-System-level signals that can be sent via process_send_signal are defined in the `subprocess::signals`` list. It is a list that is generated when the package is loaded and it contains only signals supported by the current platform (Windows or Linux).

All signals, both supported and not supported by the current platform, are also exported under their names. If a given signal is not supported on the current platform, then its value is set to NA.

Calling process_kill() and process_terminate() invokes the appropriate OS routine (waitpid() or WaitForSingleObject(), closing the process handle, etc.) that effectively lets the operating system clean up after the child process. Calling process_send_signal() is not accompanied by such clean-up and if the child process exits it needs to be followed by a call to process_wait().

process_terminate() on Linux sends the SIGTERM signal to the process pointed to by handle. On Windows it calls TerminateProcess().

process_kill() on Linux sends the SIGKILL signal to handle. On Windows it is an alias for process_terminate().

process_send_signal() sends an OS-level signal to handle. In Linux all standard signal numbers are supported. On Windows supported signals are SIGTERM, CTRL_C_EVENT and CTRL_BREAK_EVENT. Those values will be available via the signals list which is also attached in the package namespace.

Usage

signals

process_terminate(handle)

process_kill(handle)

process_send_signal(handle, signal)

SIGABRT

SIGALRM

SIGCHLD

SIGCONT

SIGFPE

SIGHUP

SIGILL

SIGINT

SIGKILL

SIGPIPE

SIGQUIT

SIGSEGV

SIGSTOP

SIGTERM

SIGTSTP

SIGTTIN

SIGTTOU

SIGUSR1

SIGUSR2

CTRL_C_EVENT

CTRL_BREAK_EVENT

Arguments

handle

Process handle obtained from spawn_process().

signal

Signal number, one of names(signals).

Format

An object of class list.

Details

In Windows, signals are delivered either only to the child process or to the child process and all its descendants. This behavior is controlled by the termination_mode argument of the subprocess::spawn_process() function. Setting it to TERMINATION_GROUP results in signals being delivered to the child and its descendants.

See Also

spawn_process()

Examples

Run this code
# NOT RUN {
# send the SIGKILL signal to bash
h <- spawn_process('bash')
process_signal(h, signals$SIGKILL)
process_signal(h, SIGKILL)

# is SIGABRT supported on the current platform?
is.na(SIGABRT)
# }
# NOT RUN {
# }
# NOT RUN {
# Windows
process_send_signal(h, SIGTERM)
process_send_signal(h, CTRL_C_EVENT)
process_send_signal(h, CTRL_BREAK_EVENT)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab