* SIGXFSZ signal creates defunct process in multithreaded program!!!
@ 2004-06-28 13:15 Pijush Kumar Koley
[not found] ` <2B721C6525F0D411B1E900B0D0226BDD05010A0D@mohmsg01.ad.infos ys.com>
0 siblings, 1 reply; 3+ messages in thread
From: Pijush Kumar Koley @ 2004-06-28 13:15 UTC (permalink / raw)
To: gcc-help
Hi!
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<stdlib.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];
}ChildInfo;
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);
exit(0);
}
int main ()
{
struct sigaction sigact;
sigset_t sigset;
sigact.sa_handler = NULL;
sigact.sa_sigaction = NULL;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
pthread_t thread_id[5];
strcpy(child[0].name,"PROCESS1");
strcpy(child[1].name,"PROCESS2");
strcpy(child[2].name,"PROCESS3");
strcpy(child[3].name,"PROCESS4");
strcpy(child[4].name,"PROCESS5");
// Handle signal
sigact.sa_handler =&sighandler1;
sigfillset(&sigact.sa_mask);
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.
Regards
-Pijush
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: SIGXFSZ signal creates defunct process in multithreaded program!!!
@ 2004-06-28 16:30 lrtaylor
0 siblings, 0 replies; 3+ messages in thread
From: lrtaylor @ 2004-06-28 16:30 UTC (permalink / raw)
To: pijush_koley, gcc-help
Don't know that this has anything to do with your problem or not, but you should use '-pthread' instead of '-lpthread'. -pthread sets a couple more options generally needed for threaded programs and also links to the pthread library.
Thanks,
Lyle
-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On Behalf Of Pijush Kumar Koley
Sent: Monday, June 28, 2004 7:15 AM
To: gcc-help@gcc.gnu.org
Subject: SIGXFSZ signal creates defunct process in multithreaded program!!!
Hi!
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<stdlib.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];
}ChildInfo;
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);
exit(0);
}
int main ()
{
struct sigaction sigact;
sigset_t sigset;
sigact.sa_handler = NULL;
sigact.sa_sigaction = NULL;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
pthread_t thread_id[5];
strcpy(child[0].name,"PROCESS1");
strcpy(child[1].name,"PROCESS2");
strcpy(child[2].name,"PROCESS3");
strcpy(child[3].name,"PROCESS4");
strcpy(child[4].name,"PROCESS5");
// Handle signal
sigact.sa_handler =&sighandler1;
sigfillset(&sigact.sa_mask);
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.
Regards
-Pijush
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-06-28 16:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-28 13:15 SIGXFSZ signal creates defunct process in multithreaded program!!! Pijush Kumar Koley
[not found] ` <2B721C6525F0D411B1E900B0D0226BDD05010A0D@mohmsg01.ad.infos ys.com>
2004-06-28 13:34 ` Eljay Love-Jensen
2004-06-28 16:30 lrtaylor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).