LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Read file in folder /proc/"pid"/fd/0 in ubuntu v11.10? (https://www.linuxquestions.org/questions/linux-newbie-8/read-file-in-folder-proc-pid-fd-0-in-ubuntu-v11-10-a-4175417416/)

newbie_member 07-18-2012 11:49 AM

Read file in folder /proc/"pid"/fd/0 in ubuntu v11.10?
 
I cannot read file in folder /proc/"pid"/fd/0 which I need read it from C language to display screen.

Thank you so much!

ppoulsen 07-18-2012 12:08 PM

Have you tried running your program with superuser privileges?
Code:

sudo ./my_program

pixellany 07-18-2012 12:26 PM

Quote:

Originally Posted by newbie_member (Post 4731825)
I cannot read file in folder /proc/"pid"/fd/0 which I need read it from C language to display screen.

Thank you so much!

Please confirm that you want to use a C program to read this file.

What happens when you try to read it?

On my system, I randonly checked some processes, and it seems that fd0 typically points to /dev/null. What would you expect to accomplish by reading from there?

newbie_member 07-18-2012 12:42 PM

Oh sorry, I only want get information TTY of a process, but I don't know read it from C language.

Ex: commands "ps -A" in terminal

Result:
PID TTY TIME CMD

2935 ? 00:00:00 gnome-pty-helpe
2936 pts/0 00:00:00 bash

pixellany 07-19-2012 05:05 AM

Do you want to find if a process uses a TTY?

In BASH, you could do:

Code:

ls -l /proc/<PID>/fd | grep tty


All times are GMT -5. The time now is 01:50 AM.