1

We Control a process by control keys (CTRL+C,CTRL+D,CTRL+Z,...) in the Linux terminal.you can find some of them here:

https://www.howtogeek.com/howto/ubuntu/keyboard-shortcuts-for-bash-command-shell-for-ubuntu-debian-suse-redhat-linux-etc/

and Control Characters: https://en.wikipedia.org/wiki/Control_character

I found that pressing these keys sends a signal to the terminal.for example pressing Ctrl+D sends End-of-Transmission character (EOT) and Ctrl+Z sends substitute character(What Ctrl+C sends?EOF?)

What I want to do is the same for php subprocesses.

We create a process and control it by pipes.Here is an example:

<?php
$descriptorspec = array(
    0 => array("pipe", "r"),//STDIN we write to it
    1 => array("pipe", "w"),//STDOUT we read output from it
    2 => array("pipe", "w"));//STDERR we read error output from it

$process = proc_open("/bin/bash", $descriptorspec, $pipes);//open the process.I open bash here

$STDINVal="WhatShouldBeSentToProcessToDo(Ctrl+C,Ctrl+D,...)?";//We set input here

fwrite($pipes[0],$STDINVal);//We send input to the process by writing it to STDIN
fclose($pipes[0]);
?>

My question is How can I send control signals to the process? Thanks.

RedJS
  • 11
  • 3
  • 1
    Does this help? https://stackoverflow.com/questions/23414704/sending-signals-to-a-process-opened-by-proc-open Just write a function that captures signals you're looking for, and then pass that signal via that method. – Blue Jul 15 '18 at 08:17
  • 1
    Thanks a lot! I was thinking posix_kill is for just killing the process as it's name is posix_kill! I found signals here:http://php.net/manual/en/pcntl.constants.php – RedJS Jul 15 '18 at 08:30

0 Answers0