This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

SIGXFSZ signal creates defunct process in multithreaded program!!!


 I am getting a strange problem on Red Hat Linux 2.1 AS with v 2.96 for a multithreaded program when it is getting a SIGXFSZ signal. Here is my sample code (say test.cpp):

----------------------------------------------------------------------------#include <pthread.h>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>

using namespace std;

typedef struct _childinfo
        int        pid, crashcount;
        char         name[10];

static ChildInfo child[5];

void* Write_to_a_file (void* unused)
        char letter[512];

        pid_t pid = getpid();
        sprintf(letter, "The process id that has started is %d \n", pid);
        printf ("The process id that has started is %d \n", pid);
        FILE *fp1 = fopen ("/tmp/Pijush-Signal", "a+");
        fprintf (fp1, "%s\n", letter);
        fclose (fp1);

        sprintf (letter, "AAAAAAAAAAAABBBBBBBBBBB");

        FILE *fp = fopen ("/tmp/Pijush-Test", "a+");
        while (1)
                fprintf (fp, "%s\n", letter);
        fclose (fp);
        return NULL;

void sighandler1 (int sig)
        int i;
        char    message[256];

        sprintf (message, "Received SIGNAL %d", sig);
        FILE *fp = fopen ("/tmp/Pijush-Signal", "a+");
        fprintf (fp, "%s\n", message);

//      cout << "From sighandler\n";
        pid_t tid = getpid();
        printf ("The process id that caught the signal is %d \n", tid);
        sprintf(message,"The process id that caught the signal is %d \n", tid);
        fprintf (fp, "%s\n", message);

        sprintf(message, "Exiting due to signal %d", sig);
        fprintf (fp, "%s\n", message);
        fclose (fp);

int main ()
        struct sigaction sigact;
        sigset_t sigset;

        sigact.sa_handler = NULL;
        sigact.sa_sigaction = NULL;
        sigact.sa_flags = 0;

        pthread_t thread_id[5];


        // Handle signal
        sigact.sa_handler =&sighandler1;

        sigaction(SIGXFSZ, &sigact, NULL);
        cout << "Creating thread\n";
        for (int i=0; i <5; i++)
                pthread_create(&thread_id[i], NULL, &Write_to_a_file, NULL);
        cout << "threads have been created\n";
        while (1)
                cout << ".";
        return 0;

I have compiled the above code with following options

[%]g++ -o test test.cpp -lpthread

Before execution of the program I have set maximum file limit to 2024 blocks [using ulimit -f 2024 command]
After that I have executed test. After few minutes the process hangs and "ps -ef" command produces the following output.

[%]$ ps -ef|grep test
pkoley   25590 25393  4 18:33 pts/12   00:00:00 ./test
pkoley   25591 25590  0 18:33 pts/12   00:00:00 ./test
pkoley   25592 25591  3 18:33 pts/12   00:00:00 ./test
pkoley   25593 25591  0 18:33 pts/12   00:00:00 ./test
pkoley   25594 25591  0 18:33 pts/12   00:00:00 ./test
pkoley   25595 25591  0 18:33 pts/12   00:00:00 [test <defunct>]
pkoley   25596 25591  0 18:33 pts/12   00:00:00 [test <defunct>]
pkoley   25598 25462  0 18:33 pts/13   00:00:00 grep test

But the same program terminates gracefully on Solaris 2.8 with Sun Workshop v6.0 C++ compiler. Can anyone please help me to sort out the problem?

Thanks in advance.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]