- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: C : Using signals with the libpthread library
Operating System - HP-UX
1756816
Members
2698
Online
108853
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
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
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
тАО02-08-2002 06:22 PM
тАО02-08-2002 06:22 PM
C : Using signals with the libpthread library
Hi, I have run into a problem when porting our application. The app is using a combination of signals and the sleep() system call. We recently had to add the libpthread to the list of libraries to link with, due to upgrading the product (ZCOM) that we are linking to, and this changed the behavior of the application. Here is an explanation. The app sets up a function to call in the sigaction for the SIGALRM signal.
in the code, some logic requires the alarm() call to be invoked, to wake up the process during a sleep() function. The SIGALRM signal handler sets a variable to 1. Below is a trimmed down example.
/* start of x.c */
#include
#include
int got_it = 0;
void H_alarm()
{
got_it = 1;
}
main()
{
struct sigaction act;
act.sa_flags = 0;
act.sa_handler = H_alarm;
sigaction(SIGALRM, &act, NULL);
alarm(5);
sleep(10);
if (got_it) {
printf("WENT INTO ALARM HANDLER\n");
} else {
printf("DID NOT GO INTO ALARM HANDLER\n");
}
}
/* end of x.c */
Two options...
1) cc -o x x.c
2) cc -o x x.c -lpthread
If linked without libpthread.a,
the response is WENT INTO ALARM HANDLER, after
the 5 seconds. If linked WITH libpthread.a,
the process still ends after 5 seconds, but it does not invoke the handler, and will print the second statement.
There are probably other ways to re-design the app, but it is a large app, and I would prefer if someone knew if there was a different compilation option, or additional value to set which would force the behavior to be the same as it is w/o linking to pthread.
Can anyone help? Thanks in advance!!
in the code, some logic requires the alarm() call to be invoked, to wake up the process during a sleep() function. The SIGALRM signal handler sets a variable to 1. Below is a trimmed down example.
/* start of x.c */
#include
#include
int got_it = 0;
void H_alarm()
{
got_it = 1;
}
main()
{
struct sigaction act;
act.sa_flags = 0;
act.sa_handler = H_alarm;
sigaction(SIGALRM, &act, NULL);
alarm(5);
sleep(10);
if (got_it) {
printf("WENT INTO ALARM HANDLER\n");
} else {
printf("DID NOT GO INTO ALARM HANDLER\n");
}
}
/* end of x.c */
Two options...
1) cc -o x x.c
2) cc -o x x.c -lpthread
If linked without libpthread.a,
the response is WENT INTO ALARM HANDLER, after
the 5 seconds. If linked WITH libpthread.a,
the process still ends after 5 seconds, but it does not invoke the handler, and will print the second statement.
There are probably other ways to re-design the app, but it is a large app, and I would prefer if someone knew if there was a different compilation option, or additional value to set which would force the behavior to be the same as it is w/o linking to pthread.
Can anyone help? Thanks in advance!!
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2002 10:29 AM
тАО02-12-2002 10:29 AM
Re: C : Using signals with the libpthread library
Hi Rick,
sleep() behaves differently in a multi-threaded environment. From the sleep manpage:
If a SIGALRM is generated for a multi-threaded process, it may not be delivered to a thread currently in sleep().
I am not familiar with your application that uses sleeps and alarms, but you could use sigwait() to block your program until it receives a SIGALRM.
Hope that helps,
Jason
sleep() behaves differently in a multi-threaded environment. From the sleep manpage:
If a SIGALRM is generated for a multi-threaded process, it may not be delivered to a thread currently in sleep().
I am not familiar with your application that uses sleeps and alarms, but you could use sigwait() to block your program until it receives a SIGALRM.
Hope that helps,
Jason
[Insert humorous and/or inspirational quote here]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-16-2002 01:32 AM
тАО05-16-2002 01:32 AM
Re: C : Using signals with the libpthread library
Hello Rick,
Did you finally find a solution to your problem concerning SIGALRM signal handler when you link your program with libpthread library, or did you have to look for an alternate way to do what you wanted to do ?
I'm having the exact same problem (messages posted on last tuesday and wednesday), but so far could not find anybody to help and am still trying to solve it.
Hope you get this message. Thank you in advance.
Regards
Did you finally find a solution to your problem concerning SIGALRM signal handler when you link your program with libpthread library, or did you have to look for an alternate way to do what you wanted to do ?
I'm having the exact same problem (messages posted on last tuesday and wednesday), but so far could not find anybody to help and am still trying to solve it.
Hope you get this message. Thank you in advance.
Regards
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