-   Programming (
-   -   int values from function main (

shifter 05-06-2007 06: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

How can I solve this problem?

Thank you for helping in advance.

reverse 05-06-2007 07:09 AM

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


man 3 wait

jim mcnamara 05-06-2007 07: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.


volatile sig_atomic_t keep_on_going=1;


int main(int argc, char **argv)

  return keep_on_going;

shifter 05-06-2007 07:45 AM

What is _t in sig_atomic_t?

jim mcnamara 05-06-2007 12:17 PM

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:

typedef int sig_atomic_t;

shifter 05-07-2007 02: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 05:54 PM

Oh dear.

ENOMEM is an errorcode, defined in errno.h

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

All times are GMT -5. The time now is 08:30 PM.