A friend, using a remote machine, SSHed to my machine and ran the following python script:

while (1):

....print "hello world"

(this script simply prints 'hello world' continuously).

I am now logged in to my machine. How can I see the output of the script my friend was running?

if it helps, I can 'spot' the script my friend is using:

me@home:~$ ps aux | grep justprint.py

friend 7494 12.8 0.3 7260 3300 ? Ss 17:24 0:06 python TEST_AREA/justprint.py

friend 7640 0.0 0.0 3320 800 pts/3 S+ 17:25 0:00 grep --color=auto just

what steps should I take in order to view the "hello world" messages on my screen?


2 Answers 2


You generally can't see the output of anther person's program. See over in that column where your grep command is running on tty pts/3, and your friend's is ?, which means it's detached from the terminal.

You could see where the output is going with ls -l /proc/7494/fd/ (where 7494 is the process ID of your friend's process) — although if you're not running as root, you probably can't even look, for security reasons. (So try sudo ls -l /proc/7494/fd/.)

There are horrible, horrible, kludgy things you might be able to do to change where the output of the program goes. But in general, you can't and shouldn't.

If your friend wants to share the output with you, and approach would be to redirect the output of the program to a file, and then make that file readable by you:

$ python -u TEST_AREA/justprint.py > /tmp/justprint.out &
$ chmod a+r /tmp/justprint.out

(Where in this case "readable by you" is "readable by everyone"; with a little more work you can set up a shared group so just the two of you can exchange output.)

(And be aware that python buffers output by default — turning that off is what the -u is for.)


If you have root access on the machine and your friend is willing to execute some commands, it is possible:

  1. [Root] screen has to be setuid root: chmod u+s /usr/bin/screen
  2. [Friend] starts screen, he can give the session a name, makes it easier: screen -S "shared_session"
  3. [Friend] enables multiuser mode: Ctrl-a :multiuser on
  4. [Friend] enables you to access his screen session: Ctrl-a :acladd you
  5. [Friend] (Optional) restrictes your access to read-only: Ctrl-a :aclchg you -w "#"
  6. [You] attach onto friends screen: screen -x friend/shared_session

The setuid root is maybe a bit dangerous...

  • does it have to be suid? Dec 13, 2010 at 9:58
  • if not, screen will exit with: Must run suid root for multiuser support.
    – wag
    Dec 13, 2010 at 10:05
  • 1
    Using screen was also suggested at the crosspost of this question to stackoverflow: stackoverflow.com/questions/4425308/view-script-over-ssh/… Note that screen -t will work fine with no setuid root set.
    – kasterma
    Dec 13, 2010 at 13:50
  • @kasterma: I'm a bit skeptic if user A can actually attach to user B's screen without suid/root rights, can you explain that further?
    – wag
    Dec 13, 2010 at 18:03
  • @wag you are right; everything but step 6 works without, and that is the step I didn't bother (but clearly should have) testing. (it might have been nice if step 4 gave a warning about this)
    – kasterma
    Dec 13, 2010 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.