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 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;
}