LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-06-2007, 06:07 AM   #1
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Rep: Reputation: 30
int values from function main


Hi all, I am a new problem...
I am creating a tool (daemon) which monitors filesystem, but
I want that function main returns a integer when daemon stopped
or when there are problems. The integer numbers must are dependant from
errors.

How can I solve this problem?

Thank you for helping in advance.
 
Old 05-06-2007, 07:09 AM   #2
reverse
Member
 
Registered: Apr 2007
Distribution: Gentoo
Posts: 337

Rep: Reputation: 30
Are you talking about something like .. wait() + WEXITSTATUS() ? See the manual page for `wait`:

Code:
man 3 wait
 
Old 05-06-2007, 07:28 AM   #3
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
Use a global variable to keep the process running. When there's a problem, set the value to some pre-defined exit code: 0 == normal exit, 4 == ENOMEM and so on.

Code:
volatile sig_atomic_t keep_on_going=1;

.......

int main(int argc, char **argv)
{
   while(keep_on_going)==1)
   {


   }
   return keep_on_going;
}
 
Old 05-06-2007, 07:45 AM   #4
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Original Poster
Rep: Reputation: 30
What is _t in sig_atomic_t?
 
Old 05-06-2007, 12:17 PM   #5
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
sig_atomic_t is the integer datatype on your particular box that is guaranteed to be atomic - able to be changed - ie. it can't be interrupted, it is guaranteed to complete regardless of signals or OS context switching for simple assigment/arithmetic operations like i=4; i++;

_t is a convention meaning it is a typedef -- for example:
Code:
typedef int sig_atomic_t;
 
Old 05-07-2007, 02:36 PM   #6
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Original Poster
Rep: Reputation: 30
How much values can I to set?
What meaning ENOMEM value?
Are there standard values or I must create my personal values?
 
Old 05-07-2007, 05:54 PM   #7
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
Oh dear.

ENOMEM is an errorcode, defined in errno.h

Follow the links on this page about daemon code development --

http://www.unix.com/showthread.php?t...ht=make+daemon
 
  


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
int * function(void)??? kalleanka Programming 5 08-01-2006 10:37 AM
main(int argc, char **argv) Longinus Programming 4 06-12-2004 08:22 AM
A main can be changed by a function local without passing anything to the function? ananthbv Programming 10 05-04-2004 02:31 PM
Hash-Function (string to int) Hady Programming 5 04-05-2004 02:53 AM
int main() gurra Programming 1 02-02-2002 07:28 AM


All times are GMT -5. The time now is 05:54 PM.

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