I have a long running
bash instance (inside a
screen session) that is executing a complex set of commands inside a loop (with each loop doing pipes, redirects, etc).
The long command line was written inside the terminal - it's not inside any script. Now, I know the bash process ID, and I have root access - how can I see the exact command line being executed inside that
bash$ echo $$ 1234 bash$ while true ; do \ someThing | somethingElse 2>/foo/bar | \ yetAnother ; sleep 600 ; done
And in another shell instance, I want to see the command line executed inside PID 1234:
bash$ echo $$ 5678 bash$ su - sh# cd /proc/1234 sh# # Do something here that will display the string \ 'while true ; do someThing | somethingElse 2>/foo/bar | \ yetAnother ; sleep 600 ; done'
Is this possible?
Adding counter-examples for some answers I've got.
About using the
/proc/PID: that doesn't work, at least not in my scenario. Here's a simple example:
$ echo $$ 8909 $ while true ; do echo 1 ; echo 2>/dev/null ; sleep 30 ; done
In another shell:
$ cat /proc/8909/cmdline bash
ps -p PID --noheaders -o cmdis just as useless:
$ ps -p 8909 --no-headers -o cmd bash
ps -eafis also not helpful:
$ ps -eaf | grep 8909 ttsiod 8909 8905 0 10:09 pts/0 00:00:00 bash ttsiod 30697 8909 0 10:22 pts/0 00:00:00 sleep 30 ttsiod 31292 13928 0 10:23 pts/12 00:00:00 grep --color=auto 8909
That is, there's no output of the ORIGINAL command line, which is what I'm looking for - i.e the
while true ; do echo 1 ; echo 2>/dev/null ; sleep 30 ; done.