bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Daemons - Using the process class?


From: David Sugar
Subject: Re: Daemons - Using the process class?
Date: Tue, 12 Jun 2007 08:30:19 -0400
User-agent: Thunderbird 1.5.0.8 (X11/20061107)

What attach does is dissasociate the controlling terminal and
potentially associate with a new one under a new process group.  The
same code is reused for detach, which does the dissociate and single
fork on some platforms, and a dual fork on others.

Wolfgang Alper wrote:
> Hello,
> 
> Sorry, i just realized that the following is obviously wrong:
>> but this cannot work as it is defined as follows:
>> void Process::detach(void) { attach("/dev/null"); }
> 
> This calls attach with "dev/null". 
> 
> Anyway, i still do not get it to work so any help is apprecicated.
> 
> Example:
> main() {
>   cout << "before creating the daemon" <<  endl;
>   // ? how to setup the parent to wait (or not) for the child?
>   // cannot use detach because it would close all handles of the child.
>   Process::attach("what goes here?");
>   If ("what goes here?") {
>     char buffer[32];
>     cout << "i am the child" << endl;
>     cin.getline(buffer, sizeof(buffer));
>     cout << "Child: You entered:" << buffer << "\nDone:" << endl;  
>     exit(0);
>   } else {
>     cout << "i am the parent - Done" << endl;         
>     exit(0);
>   }
> }
> 
> Regards 
> 
> Wolfgang 
> 
> 
> Am Mittwoch, 9. Mai 2007 17:21 schrieb Wolfgang Alper:
>> Hello,
>> I am using commoncpp2-1.5.6 under linux.
>> I tried using the process class but it seems i miss a piece.
>> Basicallyl i would like to create a daemon (using linux) based on fork.
>> i thought i would have to call: Process::detach();
>> From the docs
>> "Detach current process into a daemon, posix only. Perhaps a similar method
>> can be used for creating win32 "services"?"
>>
>> but this cannot work as it is defined as follows:
>> void Process::detach(void) { attach("/dev/null"); }
>>
>> So it seems that :
>> void Process::attach (const char * devname )
>> "Attach the current process to another device or i/o session. It is
>> deamonified and dissasociated with the prior parent process and controlling
>> terminal."
>> is the better choice.
>>
>> But i still do not get it to work.
>> -What to pass as devname?
>> -How do it get the PID to know wether i am the child or parent?
>> -How can i pass parameter (like waitpid) to decide wether the parent wants
>> to wait for the child or not?
>>
>> I am sure i missunderstood something, so if anyone could give an example on
>> how to use this class, this would be great.
>>
>> Thanks
>>
>> Wolfgang
>>
>>
>>
>>
>>
>> _______________________________________________
>> Bug-commoncpp mailing list
>> address@hidden
>> http://lists.gnu.org/mailman/listinfo/bug-commoncpp
> 
> 
> _______________________________________________
> Bug-commoncpp mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/bug-commoncpp

Attachment: dyfet.vcf
Description: Vcard


reply via email to

[Prev in Thread] Current Thread [Next in Thread]