If you have a process that is waiting for user-input from the stdin
scope, then how can you supply that user-input from a second terminal ?
Specifically, if I run the c-program
while(1){
fgets(string, len, stdin);
string[strlen(string)-1] = 0;
if(strcmp("Stop", string) == 0){
printf("Gotcha");
return 1;
}
}
then how can I supply the string "Stop" to stdin
of that process from another process, such that the first process will stop (and print "Gotcha") ?
I've tried to run the c-program in terminal 'pts/0' and open a new terminal ('pts/1') with commands:
$ echo "Stop" > /proc/<pid>/fd/0
$ echo "Stop" > /dev/pts/0
where pid is the process id. The "Stop"-command is "repeated" in the first shell, but the process does not receive it.