Linux / how to check if subprocess is still alive

  • Thread starter Sigfried Manner
  • Start date
S

Sigfried Manner

Hello NG!

I have following situation:

c-prg | webprg

"c-prg" is a small c-programm which reads data from an fastCgi-Server and
writes them to stdout.
The stdout is piped into webprg.
"webprg" is an 4th-GL Application that reads Data from StdIn and writes Data
to an fifo-pipe.
"c-prg" reads data from the fifo-pipe and writes them back to the
FastCGI-Server.

Sometimes "webprg" stopps for different reasons.
But "c-prg" is still alive and the Fast-CGI-Server has no reason to restart
the process-chain.
So, is there a way to determine if a subprocess is still alive.
But keep in mind, that the subprocess (webprg) is not forked inside the
parentprocess. It is just a pipe-chain.

The following c-source is from "c-prg"


Many thanks for any ideas in advance!
Sig






/*
*
* Produce a page containing all the inputs (fcgiapp version)
*
*
* Copyright (c) 1996 Open Market, Inc.
*
* See the file "LICENSE.TERMS" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
*/
#ifndef lint
static const char rcsid[] = "$Id: echo-x.c,v 1.1 2001/06/19 15:06:17 robs
Exp $";
#endif /* not lint */

#include <stdio.h>
#include "fcgi_config.h"

#include <stdlib.h>

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#ifdef _WIN32
#include <process.h>
#else
extern char **environ;
#endif

#include "fcgiapp.h"

#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>

static void PrintEnv(FCGX_Stream *out, char *label, char **envp)
{
for( ; *envp != NULL; envp++) {
printf("%s\n", *envp);
}
}

int main ()
{
FCGX_Stream *in, *out, *err;
FCGX_ParamArray envp;
int count = 0;
int in_count;

int fd_fifo, pid;
char buffer[4096];
char fifo[30];
mode_t mode = 0666;

pid = getpid();

sprintf(fifo, "/tmp/fifo_%d", pid);
if((mkfifo(fifo, mode)) == -1) {
FCGX_FPrintF(out,"Cannot create %s",fifo);
return (-1);
}
printf("%s\n", fifo);


while (FCGX_Accept(&in, &out, &err, &envp) >= 0) {
char *contentLength = FCGX_GetParam("CONTENT_LENGTH", envp);
int len = 0;

++count;

if (contentLength != NULL)
len = strtol(contentLength, NULL, 10);

if (len <= 0) {
}
else {
int i, ch;

printf("POSTDATA=");
for (i = 0; i < len; i++) {
if ((ch = FCGX_GetChar(in)) < 0) {
FCGX_FPrintF(out,
"Error: Not enough bytes received on standard
input<p>\n");
break;
}
putchar(ch);
}
printf("\n");
}

PrintEnv(out, "Request environment", envp);
PrintEnv(out, "Initial environment", environ);
printf("<<EOF>>\n");
fflush (stdout);

fd_fifo=open(fifo, O_RDONLY);
if (fd_fifo != -1) {
while(1) {

/* in_count = read(fd_fifo,&buffer,1);
if (!in_count) {
break;
}
FCGX_PutChar(buffer, out);
*/
in_count = read(fd_fifo,&buffer,4096);
if (!in_count) {
break;
}
FCGX_PutStr(buffer,in_count,out);

}
close(fd_fifo);
}
else {
FCGX_FPrintF(out, "Could not open fifo-pipe");
}
} /* while */

unlink(fifo);
return 0;
}
 
I

Irrwahn Grausewitz

Hello NG!

I have following situation:

c-prg | webprg
"c-prg" is a small c-programm which reads data from an fastCgi-Server and
writes them to stdout.
The stdout is piped into webprg.
"webprg" is an 4th-GL Application that reads Data from StdIn and writes Data
to an fifo-pipe.
"c-prg" reads data from the fifo-pipe and writes them back to the
FastCGI-Server.
Sometimes "webprg" stopps for different reasons.
But "c-prg" is still alive and the Fast-CGI-Server has no reason to restart
the process-chain.
<BOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOM>

<SNIPped question and *nixish code>

Please ask in an ng appropriate for your problem. c.l.c discusses the
C language in its standardized (read: portable) flavours.

Sorry.

Irrwahn

PS: While reading the FAQ for c.l.c, what did made you think it's the
right place for your question?
 
P

Pieter Droogendijk

Please ask in an ng appropriate for your problem. c.l.c discusses the
C language in its standardized (read: portable) flavours.

Actually, he did about five minutes later. At least he didn't cross-post, which
would probably have resulted in extensive flaming and killfiling.
PS: While reading the FAQ for c.l.c, what did made you think it's the
right place for your question?

Probably the part that said 'Please post endless moobs of nonstandard code so
others can flame you without hesitation'. I think that's in the ten commandments
of C as well somewhere...
 
S

Sigfried Manner

Irrwahn said:
Please ask in an ng appropriate for your problem. c.l.c discusses the
C language in its standardized (read: portable) flavours.

Sorry and Thanks!

Sig
 
I

Irrwahn Grausewitz

Pieter Droogendijk said:
Probably the part that said 'Please post endless moobs of nonstandard code so
others can flame you without hesitation'. I think that's in the ten commandments
of C as well somewhere...
Yup, right next to 'Write ++i=i++; 5 times a day and be proud of it.'.
 
S

Sigfried Manner

Irrwahn said:
Yup, right next to 'Write ++i=i++; 5 times a day and be proud of it.'.

To be honest, i am not a c-programmer.
I?m developing business-applications since 15 years and (thank god!) i never
had the need to use os-system-near languages ;-)

Cheers!
Sig
 
J

Joona I Palaste

Irrwahn Grausewitz said:
Yup, right next to 'Write ++i=i++; 5 times a day and be proud of it.'.

Be proud? Of code that won't even compile? Or are you thinking of C++?
In C that should probably be "Write i=i++; 5 times a day and be proud of
it".

--
/-- Joona Palaste ([email protected]) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"That's no raisin - it's an ALIEN!"
- Tourist in MTV's Oddities
 
I

Irrwahn Grausewitz

Joona I Palaste said:
Be proud? Of code that won't even compile? Or are you thinking of C++?
In C that should probably be "Write i=i++; 5 times a day and be proud of
it".
Ah, you noticed the subtle humor. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top