I have a process that runs indefinitely until a key is pressed. I would like to use bash to inject a keystroke into this process to have it terminate. Based on this post, li
From here:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
int main(void)
{
int hTTY = open("/dev/tty1", O_WRONLY|O_NONBLOCK);
ioctl(hTTY, TIOCSTI, "b");
close(hTTY);
return 0;
}
The terminal and keystroke are hardcoded in this example, but it can be adapted to your needs.
You can do something similar in Perl:
perl -e '$TIOCSTI = 0x5412; $tty = "/dev/pts/1"; $char = "b"; open($fh, ">", $tty); ioctl($fh, $TIOCSTI, $char)'
I have to run either of these with sudo
.
what about just killing the process from a script
killall processname