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.)
- Why doesn't the shell open like it did in the first case?
In the first case, stdin
is a terminal and the shell is interactive. It waits for your commands etc.
In the second case stdin
is a pipe, and the shell is non-interactive. Your program consumes the first line on stdin
(namely the string test\n
), then the shell tries to read stdin
and sees EOF
. It exits, because that's what programs that get EOF
on input are supposed to do.
In the third case the shell again is non-interactive, for the same reason. Your scanf()
consumes the first line on stdin
(i.e. test\n
), then the shell reads ls
. The shell runs ls
, tries to read more commands, sees EOF
, and exits.
- How can I deal with this?
If by "dealing with it" you mean running an interactive shell when stdin
is connected to a pipe, the solution is to use a pty(7)
.
Best Answer
By default,
pgrep(1)
will only match against the process name. If you want to match against the full command line, use the-f
option: