James Lehman wrote:
>>C/C++ is not a language, choose one or the other and stick to it.
>
>
> I use classes with inheritance and virtual function to define my device, my
> tape, my specific tape drive, etc. The application also relies heavily on
> file descriptors, ioctl calls and signal trapping with a termination
> function. That's what I call C/C++. Parts of it a pure C. Parts of it are
> pure C++.
>
> I've also written polymorphic object oriented programming (POOP) in pure C.
<font color=purple> > <a style='text-decoration: underline;' href="http://freshmeat.net/projects/ezfb/?topic_id=901%2C100%2C101%2C111%2C112</font" target="_blank">http://freshmeat.net/projects/ezfb/?topic_id=901%2C100%2C101%2C111%2C1...lt;/fon</a>>
>
> I know the difference between C and C++.
>
>
>>You probably don't want to use popen and you almost certainly do not want
>
> to
>
>>use the & operator to "backgroundify" what you're running.
>
>
> Why? It works like this from a script like /etc/rc.d/rc.local.
>
> I don't get how forking twice would get me anywhere better than once.
>
>
>>what does ps aux tell you is the pid of the application that's running?
>>Sounds like a zombie to me..
>
>
> The process has a real number, but since root didn't start it, when I kill
> it or killall, I get no message of its termination. It's just gone. Since it
> has no effect on the pid or the status file, it can be started many times.
> This has a horrible effect on the machine in general.
>
>
>>You might try comp.unix.programmer in future as this isn't really an
>
> apache
>
>>specific question.
>
>
> Well it sort-of-is. It has everything to do with what the user apache can do
> on a machine that has lots of stuff owned by root AND it has to do
> specifically with the hidden shell that runs the CGI app that is inside of
> Apache and how it relates to a real shell in a real console.
>
> Smile. Be Happy. Look at some art.
<font color=purple> > <a style='text-decoration: underline;' href="http://www.akrobiz.com/pc/gallery_index.html</font" target="_blank">http://www.akrobiz.com/pc/gallery_index.html</font</a>>
>
> Take care. James.
)
>
>
>
>
Apache won't recognize that that a CGI script is done until the CGI
script and all of its subprocesses exit (or at least send an EOF to
stdout). Here is the proper method [adapted from Unix Network
Programming Volume 1 - W. Richard Stevens].
// Block the hangup (HUP) signal. This is sent to all child processes
// when their parent dies. The hangup signal's default action is to
// terminate the proces. If we don't block it, the next statement
// will terminate the parent.
signal( SIGHUP, SIG_IGN );
// Now, we fork and exit the parent. This places the process in the
// background,
if ( fork() != 0 ) exit( 0 );
// At this point, we are in the background, but still attached to the
// current login session (or CGI execution). We need to make it the
// leader of it's own session. This will prevent it from receiving
// hang up signals when the CGI script dies.
setsid();
// Now, to be sure that we don't later send output that assigns us a
// controlling terminal, we need to close all open file descriptors.
// UNIX doesn't provide a way to either close all open files or to
// determine how many descriptors we are using. We close the first
// sixteen which should be PLENTY in a newly started app (we can
// usually get away with just three, but we err on the side of safety
// here). If you have a log file open a this point, it may well be
// closed. Open your log file AFTER this segment of code.
for ( int x = 0 ; x < 16 ; x++ ) close( x );
// Now, to go from the background process to a full daemon, we need to
// fork yet again. This will make the process detached from any
// session as it's session leader (the process from the first fork)
// will be dead.
signal( SIGHUP, SIG_IGN );
if ( fork() != 0 ) exit( 0 );
// You are now a properly created demon process and may do anything
// else you like at this point. There is no stdout to printf() to.
Hope this helps.
Tim<!-- ~MESSAGE_AFTER~ -->
>> Stay informed about: CGI starting and stopping daemons.