I am using ttyecho (can be installed with yay -S ttyecho-git
) to execute a command in a separate terminal like so:
urxvt &
sudo ttyecho -n /proc/<pid-of-new-urxvt>/fd/0 <command>
It does not work because the /proc/pid-of-new-urxvt/fd/0 is a symlink that points to the /dev/pts/x of the parent terminal. In the spawned urxvt I happen to run zsh. So if I use the pid of that zsh process it works:
sudo ttyecho -n /proc/<pid-of-new-zsh-within-new-urxvt>/fd/0 <command>
How can I get the pid of the new zsh process spawned within the new urxvt process when I run urxvt &
? Or is there a different solution to achieve the same result?
urxvt &
,$!
contains the PID of the urxvt process. The zsh you are looking for, is a child process of this. Use theps
command to get a list of all processes, and pick a line which is a zsh process having the PPID which you have just found. – user1934428ps
.... now just write a program which searches the pid in the whole process list. It's just a text search. You can do it in virtually any language you like; doesn't even have to be bash. – user1934428