Issue
I have a terminal (xterm) open with bash running in it, showing a prompt. Suppose I know this running bash's pid and the tty associated with this terminal. Is there any way, not touching this terminal at all, but only use the tty and pid information, to ask this very running bash to run a command? Naively echo "command" > tty would only show the command in the terminal but bash doesn't receive it as a user input.
Solution
Use a TIOCSTI
ioctl. Example in C:
char* cmd="ls\n";
int fd = open (ptsname, O_RDWR);
while (*cmd)
{
ioctl(fd, TIOCSTI, cmd++);
}
Answered By - n. 1.8e9-where's-my-share m. Answer Checked By - Timothy Miller (WPSolving Admin)