LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   int values from function main (http://www.linuxquestions.org/questions/programming-9/int-values-from-function-main-551666/)

shifter 05-06-2007 05:07 AM

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.

reverse 05-06-2007 06:09 AM

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

Code:

man 3 wait

jim mcnamara 05-06-2007 06:28 AM

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;
}


shifter 05-06-2007 06:45 AM

What is _t in sig_atomic_t?

jim mcnamara 05-06-2007 11:17 AM

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;

shifter 05-07-2007 01:36 PM

How much values can I to set?
What meaning ENOMEM value?
Are there standard values or I must create my personal values?

jim mcnamara 05-07-2007 04:54 PM

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


All times are GMT -5. The time now is 11:34 AM.