Re: create a daemon problems
From: Steve (none_at_none.com)
Date: 05/12/03
- Next message: Derk Gwen: "Re: Setting and Using Unix Variables"
- Previous message: John Gordon: "Re: Setting and Using Unix Variables"
- In reply to: Craig: "Re: create a daemon problems"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Mon, 12 May 2003 20:23:33 +0100
Craig wrote:
> I'm trying to create a daemon, the problem im having is it
> going down to the bottom and doing the
> printf("This is by the exit zero at bottom"); line.
>
> It never going to the for loop.
>
> Ive been racking my head for the past 3 hours and cant figure it. please
> help.
> (I have also tried it withought the if statement block)
> --------------------------------------------
> if( fork() == 0 ) {
>
>
> if (test_mode != 1){
> fclose( stdin );
> fclose( stdout );
> }
> while( 1 ) {
> //////////////////////////////
>
> printf("Test");
>
> ////////////////////////////
> exit ( 0 );
>
> }
> }
>
> else {
> printf("This is by the exit zero at bottom");
> exit( 0 );
> return ( 0 );
>
>
> } /* End if( fork() ) */
>
> exit( 0 );
> return( 0 );
>
> } /* End main() */
Craig wrote:
> Sorry I meant while loop
>
>> You have no for loop in this code.
No it is going into the 'while' loop. Assuming test_mode != 1, the output
looks like this:
This is by the exit zero at bottomTest
Notice it says, 'Test' on the end, from the printf in the while loop.
A fork creates a new process in addition to the original one, and then both
run concurrently. So both branches of the 'if (fork()...)' will
execute: the child process executes the 'if' clause, and the original
process continues running and executes the 'else' clause.
- Next message: Derk Gwen: "Re: Setting and Using Unix Variables"
- Previous message: John Gordon: "Re: Setting and Using Unix Variables"
- In reply to: Craig: "Re: create a daemon problems"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|