LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   is there a way to tell if a C program is running without a terminal? (http://www.linuxquestions.org/questions/linux-general-1/is-there-a-way-to-tell-if-a-c-program-is-running-without-a-terminal-806833/)

MrUmunhum 05-09-2010 02:51 PM

is there a way to tell if a C program is running without a terminal?
 
Hi group,

I have a C program that can run disconnected ( like most ), is there a programmatical way to tel if the program is running without a terminal? Example:
nohup my-program &
What I want is to modify the program so it can be used as a HUB interface. It does Peer to Peer communication and I want to make it a server function with a command line option. Currently if I disconnect the program, it will loop on the read for stdin, I need to be able to detect that and go into 'HUB' mode.

jiml8 05-09-2010 02:56 PM

Why not just give it a command line option to close stdin, stdout, and stderr?

MrUmunhum 05-10-2010 12:09 PM

That is one option
 
Quote:

Originally Posted by jiml8 (Post 3962483)
Why not just give it a command line option to close stdin, stdout, and stderr?

If the user is smart enough at the time the program is started, that will work.

I would like to be able to programmatically correct the problem. I could close it if I get a zero length read??

stevexyz 05-10-2010 04:09 PM

Check out isatty()

Steve

MrUmunhum 05-11-2010 01:21 PM

[Solved] That's it!
 
Quote:

Originally Posted by stevexyz (Post 3963801)
Check out isatty()

Steve

Prefect, thanks.


All times are GMT -5. The time now is 02:11 PM.