Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6542597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:14:49+00:00 2026-05-25T11:14:49+00:00

I have a CGI script running on mongoose webserver written in C++ (independent of

  • 0

I have a CGI script running on “mongoose webserver” written in C++ (independent of mongoose specific APIs for portability in the future) on Ubuntu 10.04. Whenever I invoke the script from web browser (Chrome), the process works fine but when I run ps -al I see

F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
4 S     0  3567  8877  0  80   0 - 23309 hrtime pts/0    00:00:00 mongoose
4 Z     0  3585  3567  7  80   0 -     0 exit   pts/0    00:00:00 test <defunct>

I use sudo kill -9 3567 in this case to kill the parent process. I have the following code in my script.

...
#include <sys/wait.h>
...

//==========================================================================
// Define the function to be called when ctrl-c (SIGINT) signal is sent to process
static void signal_callback_handler(int signum)
{ 
    point_of_inspection( __FILE__, __func__, __LINE__, ENABLE_LOG); // Entered the routine

    // Cleanup and close up stuff here
    while(1)
    {
        if (signum == SIGTERM)
        {
            error_log_report("caught signal - premature exit",CAUGHT_SIGNAL_ERROR,ENABLE_LOG);
            break;
        }
    }
    clean_exit();
    // Terminate program
    exit(signum);
}
//======================= Zombies or <defunct> handler ========================
// Signal handler to process terminated children
static void mysig(int nsig) 
{ 
    int nStatus, nPid; 
    while(1)
    {
        if (nsig == SIGCHLD)
        {
            nPid = waitpid(-1, &nStatus, WNOHANG); 
            if(nPid<0)
            {
                error_log_report("waitpid (nPid<0)",CAUGHT_SIGNAL_ERROR,ENABLE_LOG);         
                break;               
            }
            if(nPid==0)
            {
                error_log_report("Caught Signal - Zombies <defunct> (nPid==0)",CAUGHT_SIGNAL_ERROR,ENABLE_LOG);
                break;  
            }
        } 
    }
    clean_exit();
    exit(nsig);
} 

In the main function

 int main()
 {
  //some initialization variables
  ...

     // Register signal and signal handler
     signal(SIGTERM, signal_callback_handler);

     // To clean up terminated children
     signal(SIGCHLD, mysig); 
  ...

     return 0;
 }

However, It seems to not catch any signal triggered when the user closes web browser or navigates to a different page as I do not see any logs. I am wondering if this is a bug in mongoose or my script (I do not use any fork() process or threads in my script. But mongoose does use threads. Also I do not use any mongoose webserver specific APIs in my script.).

I am referring the signal tutorial from here http://orchard.wccnet.org/~chasselb/linux275/ClassNotes/process/sigbasics.htm and
http://www.gnu.org/s/hello/manual/libc/Process-Completion.html

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:14:50+00:00Added an answer on May 25, 2026 at 11:14 am

    They updated the code in mongoose.c file to reap zombies. The following is the portion of the code.

    #if !defined(_WIN32) && !defined(__SYMBIAN32__)
      // Ignore SIGPIPE signal, so if browser cancels the request, it
      // won't kill the whole process.
      (void) signal(SIGPIPE, SIG_IGN);
      // Also ignoring SIGCHLD to let the OS to reap zombies properly.
      (void) signal(SIGCHLD, SIG_IGN);
    #endif // !_WIN32
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a CGI script that creates an image dynamically using GET data.
I have a very simple CGI webserver running using python CGIHTTPServer class. This class
I'm running Lighttpd on Cygwin. I have a Lua CGI script that calls a
I have a Python CGI script script.py running on a server. It produces a
Hey I have a windows server running python CGI scripts and I'm having a
I have a cgi script which takes form input, I want to facilitate the
I have a CGI script that prints the following on stdout: print Status: 302
I have a small cgi script that fetches and validates a configuration file for
I have a perl cgi script that's fairly resource intensive (takes about 2 seconds
I have this warning every time I run my CGI-script (output is rendered by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.