LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 05-09-2010, 03:51 PM   #1
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA
Distribution: Debian/ Fedora
Posts: 432

Rep: Reputation: 33
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.
 
Old 05-09-2010, 03:56 PM   #2
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 115Reputation: 115
Why not just give it a command line option to close stdin, stdout, and stderr?
 
Old 05-10-2010, 01:09 PM   #3
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA
Distribution: Debian/ Fedora
Posts: 432

Original Poster
Rep: Reputation: 33
That is one option

Quote:
Originally Posted by jiml8 View Post
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??
 
Old 05-10-2010, 05:09 PM   #4
stevexyz
LQ Newbie
 
Registered: Apr 2008
Location: Hampshire, UK
Distribution: None
Posts: 27

Rep: Reputation: 16
Check out isatty()

Steve
 
Old 05-11-2010, 02:21 PM   #5
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA
Distribution: Debian/ Fedora
Posts: 432

Original Poster
Rep: Reputation: 33
[Solved] That's it!

Quote:
Originally Posted by stevexyz View Post
Check out isatty()

Steve
Prefect, thanks.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about running a program from terminal window ganoo Linux - Newbie 7 11-01-2010 01:44 PM
running a program start script in terminal fenriswoolf Linux - Software 1 04-01-2008 10:25 AM
Running program from terminal with & does nothing, program stops DittoAlex Linux - General 1 10-05-2007 02:35 AM
Running a Program in a new Virtual Terminal Johnsernickle Linux - Software 2 07-09-2004 12:50 PM
Running program when terminal closed? mikeshn Linux - General 9 11-23-2002 09:00 PM


All times are GMT -5. The time now is 04:18 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration