|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Daemons - Using the process class?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 Bug-commoncpp@... http://lists.gnu.org/mailman/listinfo/bug-commoncpp |
|
|
Re: Daemons - Using the process class?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 > Bug-commoncpp@... > http://lists.gnu.org/mailman/listinfo/bug-commoncpp _______________________________________________ Bug-commoncpp mailing list Bug-commoncpp@... http://lists.gnu.org/mailman/listinfo/bug-commoncpp |
|
|
Re: Daemons - Using the process class?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 >> Bug-commoncpp@... >> http://lists.gnu.org/mailman/listinfo/bug-commoncpp > > > _______________________________________________ > Bug-commoncpp mailing list > Bug-commoncpp@... > http://lists.gnu.org/mailman/listinfo/bug-commoncpp [dyfet.vcf] begin:vcard fn:David Sugar n:Sugar;David org:GNU Telephony email;internet:dyfet@... tel;work:+1 201 215 2609 url:http://www.gnutelephony.org version:2.1 end:vcard _______________________________________________ Bug-commoncpp mailing list Bug-commoncpp@... http://lists.gnu.org/mailman/listinfo/bug-commoncpp |
| Free embeddable forum powered by Nabble | Forum Help |