LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 02:51 PM   #1
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA, Earth
Distribution: Debian/ Fedora/ Ubuntu/ Raspbian
Posts: 549

Rep: Reputation: 40
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, 02:56 PM   #2
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

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

Original Poster
Rep: Reputation: 40
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, 04: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, 01:21 PM   #5
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA, Earth
Distribution: Debian/ Fedora/ Ubuntu/ Raspbian
Posts: 549

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

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

Steve
Prefect, thanks.
 
  


Reply



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 12:44 PM
running a program start script in terminal fenriswoolf Linux - Software 1 04-01-2008 09:25 AM
Running program from terminal with & does nothing, program stops DittoAlex Linux - General 1 10-05-2007 01:35 AM
Running a Program in a new Virtual Terminal Johnsernickle Linux - Software 2 07-09-2004 11:50 AM
Running program when terminal closed? mikeshn Linux - General 9 11-23-2002 08:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:55 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration