[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Daemons - Using the process class?
From: |
Wolfgang Alper |
Subject: |
Re: Daemons - Using the process class? |
Date: |
Wed, 9 May 2007 17:37:23 +0200 |
User-agent: |
KMail/1.9.4 |
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