- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Problem regarding linking signal handling program ...
Operating System - HP-UX
1753899
Members
7857
Online
108809
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2001 11:23 PM
10-10-2001 11:23 PM
Problem regarding linking signal handling program with "-lpthread" option on HP-UX 11.0
Problem regarding linking signal handling program with "-lpthread" option on HP-UX 11.0
Howdy!
My program is to catch and handle sigmentation violation triggered
by out of bound array reference. When I link the program without
"-lpthread", my handler is called. When I link the program with
"-lpthread" option, my handler is not called, and the program
gives "Segmentation fault" itself. The code and execution output
is as below (it is very short):
-------Program-------
#include
#include
#include
#include
float a[100];
void sig_handler2( int sig_num ) {
printf( " - handler2: sig_num = %d\n", sig_num ); fflush( stdout );
exit(1);
}
void set_signal( void ) {
if ( signal( SIGSEGV, sig_handler2 ) == SIG_ERR ) {
fprintf( stderr, "can not set handler for SIGSEGV\n" );
exit(1);
}
}
void main() {
int i, ip=0;
int kk = 500000;
set_signal();
printf( " - start\n" );
for (i=0; i a[i] = i*i;
}
}
-------Compiling-------
make native.handle
cc +O2 -c sig.native.c
cc +O2 -o native.handle sig.native.o
make native.wrong
cc +O2 -c sig.native.c
cc +O2 -o native.wrong sig.native.o -lpthread
-------Execution --------
./native.handle
- start
- handler2: sig_num = 11
./native.wrong
- start
Segmentation fault
--------------------------
Also, I changed my signal handling code to use "POSIX sigaction()".
When I link the program without "-lpthread", the handler is called.
When I link the program with "-lpthread", the program is just hanging
there. The code and execution output is as below:
-------Program --------
#include
#include
#include
#include
float hao[100];
void sig_handler2( int sig_num ) {
printf( " - handler2: signo = %d\n", sig_num ); fflush( stdout );
exit(1);
}
void set_signal( void ) {
struct sigaction sact;
sact.sa_handler = sig_handler2;
sact.sa_flags = 0;
sigemptyset( &sact.sa_mask );
if (sigaction( SIGSEGV, &sact, (struct sigaction *) NULL ) < 0) {
fprintf( stderr, "SIGSEGV not set\n" );
exit(1);
}
}
void main() {
int i, ip=0;
int kk = 500000;
set_signal();
printf( " - start\n" );
for (i=0; i hao[i] = i*i;
}
}
-------Compiling --------
make posix.handle
cc +O2 -c sig.posix.c
cc +O2 -o posix.handle sig.posix.o
make posix.wrong
cc +O2 -c sig.posix.c
cc +O2 -o posix.wrong sig.posix.o -lpthread
-------Execution --------
./posix.handle
- start
- handler2: signo = 11
./posix.wrong
- start
--------------------------
Note:
1. machine: hp v-class
os: hp-ux 11.0
2. The reason I encountered this problem is that I was trying to use signal
handler to catch sigmentation violation introduced by out of bound array
reference in parallel loop. Parallel program is always linked with
"-lpthread" option.
Howdy!
My program is to catch and handle sigmentation violation triggered
by out of bound array reference. When I link the program without
"-lpthread", my handler is called. When I link the program with
"-lpthread" option, my handler is not called, and the program
gives "Segmentation fault" itself. The code and execution output
is as below (it is very short):
-------Program-------
#include
#include
#include
#include
float a[100];
void sig_handler2( int sig_num ) {
printf( " - handler2: sig_num = %d\n", sig_num ); fflush( stdout );
exit(1);
}
void set_signal( void ) {
if ( signal( SIGSEGV, sig_handler2 ) == SIG_ERR ) {
fprintf( stderr, "can not set handler for SIGSEGV\n" );
exit(1);
}
}
void main() {
int i, ip=0;
int kk = 500000;
set_signal();
printf( " - start\n" );
for (i=0; i
}
}
-------Compiling-------
make native.handle
cc +O2 -c sig.native.c
cc +O2 -o native.handle sig.native.o
make native.wrong
cc +O2 -c sig.native.c
cc +O2 -o native.wrong sig.native.o -lpthread
-------Execution --------
./native.handle
- start
- handler2: sig_num = 11
./native.wrong
- start
Segmentation fault
--------------------------
Also, I changed my signal handling code to use "POSIX sigaction()".
When I link the program without "-lpthread", the handler is called.
When I link the program with "-lpthread", the program is just hanging
there. The code and execution output is as below:
-------Program --------
#include
#include
#include
#include
float hao[100];
void sig_handler2( int sig_num ) {
printf( " - handler2: signo = %d\n", sig_num ); fflush( stdout );
exit(1);
}
void set_signal( void ) {
struct sigaction sact;
sact.sa_handler = sig_handler2;
sact.sa_flags = 0;
sigemptyset( &sact.sa_mask );
if (sigaction( SIGSEGV, &sact, (struct sigaction *) NULL ) < 0) {
fprintf( stderr, "SIGSEGV not set\n" );
exit(1);
}
}
void main() {
int i, ip=0;
int kk = 500000;
set_signal();
printf( " - start\n" );
for (i=0; i
}
}
-------Compiling --------
make posix.handle
cc +O2 -c sig.posix.c
cc +O2 -o posix.handle sig.posix.o
make posix.wrong
cc +O2 -c sig.posix.c
cc +O2 -o posix.wrong sig.posix.o -lpthread
-------Execution --------
./posix.handle
- start
- handler2: signo = 11
./posix.wrong
- start
--------------------------
Note:
1. machine: hp v-class
os: hp-ux 11.0
2. The reason I encountered this problem is that I was trying to use signal
handler to catch sigmentation violation introduced by out of bound array
reference in parallel loop. Parallel program is always linked with
"-lpthread" option.
student
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2001 11:06 AM
10-11-2001 11:06 AM
Re: Problem regarding linking signal handling program with "-lpthread" option on HP-UX 11.0
The heart of your problem in the test program is that you are writing all over global data, including pthread synchronization variables.
The signal handler spins on a broken spinlock variable when you call printf or even exit().
You can make your example work by changing the
hao[i] = i*i;
line to a read-
ip += hao[i];
That gets a signal without overwriting all that memory.
You should also be including pthread.h and compiling with -D_POSIX_C_SOURCE=199506L as documented in "man pthread".
You really should not be using printf in a signal handler. The stdio functions are not reentrant. You could get in more trouble when handling a signal raised within a stdio function.
The signal handler spins on a broken spinlock variable when you call printf or even exit().
You can make your example work by changing the
hao[i] = i*i;
line to a read-
ip += hao[i];
That gets a signal without overwriting all that memory.
You should also be including pthread.h and compiling with -D_POSIX_C_SOURCE=199506L as documented in "man pthread".
You really should not be using printf in a signal handler. The stdio functions are not reentrant. You could get in more trouble when handling a signal raised within a stdio function.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP