Operating System - Linux
1832674 Members
3020 Online
110043 Solutions
New Discussion

Re: Problems with SIGTERM and libBSD (HP-UX B.11.00 U 9000/800)

 
jose_lius_fdez_diaz_new
Occasional Contributor

Problems with SIGTERM and libBSD (HP-UX B.11.00 U 9000/800)

Hi,

Given then program below (foo.C):

#include
#include
#include


void sigterm_proc(int s)
{
cout << "sigterm_proc " << s << endl;
}


int main()
{

signal(SIGTERM, sigterm_proc);

sleep(60);
cout << "wake up" << endl;
}



When I compile it with "aCC -lcl k2.c" and send a SIGTERM signal (kill pid) the output is:

sigterm_proc 15
wake up


But if I compile it with "aCC -lcl -lBSD foo.C" the output is:

sigterm_proc 15

and the process doesn't wake up. Is there any bug is libBSD library?

Thanks in advance,
Jose Luis.
5 REPLIES 5
A. Clay Stephenson
Acclaimed Contributor

Re: Problems with SIGTERM and libBSD (HP-UX B.11.00 U 9000/800)

I am going to assume that your two source files "k2.c" and "foo.C" are identical; if not, your question is meaningless.

I suspect that your seconds example is not quite complete in that the program will terminate and print "wake up" after the sleep terminates.

Without testing, I am assumming that the sleep() function behaves as documented in that any caught signal terminates the sleep as well as its normal SIGALRM behavior. When libBSD is linked in, the sleep function there does not terminate upon the receipt of a caught signal.

You can verify this by using tusc to attach to the two versions but I am all but sure that it is the behavior of the sleep function that changes.
If it ain't broke, I can fix that.
Dennis Handly
Acclaimed Contributor

Re: Problems with SIGTERM and libBSD (HP-UX B.11.00 U 9000/800)

Any reason you are adding -lcl to your link line? This is added by default.
jose_lius_fdez_diaz_new
Occasional Contributor

Re: Problems with SIGTERM and libBSD (HP-UX B.11.00 U 9000/800)


What is useful for the libBSD library? What is does change the standard behavior of sleep?

If I don't use libcl the program runs fine. I don't understand why.

Thanks for your replies.

Regards,
Jose Luis
Dennis Handly
Acclaimed Contributor

Re: Problems with SIGTERM and libBSD (HP-UX B.11.00 U 9000/800)

>What is useful for the libBSD library?

I would assume you knew that since you must have some good reason for using it?? If not, junk it ASAP. Looking at some man pages may mention using libBSD.

>If I don't use libcl the program runs fine. I don't understand why.

I don't know either except you have libcl before AND after libBSD and that may cause libcl to use the foreign devil versions in libBSD instead of libc.
Dennis Handly
Acclaimed Contributor

Re: Problems with SIGTERM and libBSD (HP-UX B.11.00 U 9000/800)

Adding -lcl makes no difference, it is already there.

tusc shows:
libBSD:
[5134] sigaction(SIGTERM, 0x7f7f0f08, 0x7f7f0f30) ........ = 0
[5134] sigprocmask(SIG_BLOCK, 0x7f7f0ed8, 0x7f7f0ef8) .... = 0
[5134] getitimer(ITIMER_REAL, 0x7f7f0f18) ................ = 0
[5134] time(NULL) ........................................ = 1178618346
[5134] sigtimedwait(0x7f7f0f28, NULL, 0x7f7f0f48) ........ [sleeping]
[5134] Received signal 15, SIGTERM, in sigtimedwait(), [caught], no siginfo
[5134] sigtimedwait(0x7f7f0f28, NULL, 0x7f7f0f48) ........ ERR#4 EINTR
[5134] Received signal 26, SIGCONT, in sigenable(), [SIG_DFL], no siginfo
[5134] write(1, "s i g t e r m _ p r o c 1 5 \n", 16) .. = 16
[5134] sigtimedwait(0x7f7f0f28, NULL, 0x7f7f0f48) ........ [sleeping]

No libBSD:
[5253] sigprocmask(SIG_SETMASK, 0x7f7f0f60, 0x7f7f0f80) .. = 0
[5253] sigprocmask(SIG_SETMASK, 0x7f7f0f80, 0x7f7f0f60) .. = 0
[5253] sigsetreturn(0x7b036fbe, 0x6211988, 1392) ......... = 0
[5253] sigprocmask(SIG_SETMASK, 0x7f7f0f60, 0x7f7f0f80) .. = 0
[5253] sigprocmask(SIG_SETMASK, 0x7f7f0f80, 0x7f7f0f60) .. = 0
[5253] sigvec(SIGTERM, 0x7f7f0ec0, 0x7f7f0ed0) ........... = 0
[5253] sigprocmask(SIG_BLOCK, 0x7f7f0ed8, 0x7f7f0ef8) .... = 0
[5253] getitimer(ITIMER_REAL, 0x7f7f0f18) ................ = 0
[5253] time(NULL) ........................................ = 1178618480
[5253] sigtimedwait(0x7f7f0f28, NULL, 0x7f7f0f48) ........ [sleeping]
[5253] Received signal 15, SIGTERM, in sigtimedwait(), [caught], no siginfo
[5253] sigtimedwait(0x7f7f0f28, NULL, 0x7f7f0f48) ........ ERR#4 EINTR
[5253] Received signal 26, SIGCONT, in sigenable(), [SIG_DFL], no siginfo
[5253] write(1, "s i g t e r m _ p r o c 1 5 \n", 16) .. = 16
[5253] time(NULL) ........................................ = 1178618491
[5253] sigprocmask(SIG_SETMASK, 0x7f7f0ef8, NULL) ........ = 0
[5253] write(1, "w a k e u p \n", 8) ................... = 8
[5253] exit(0) ........................................... WIFEXITED(0)


So libBSD probably changes signal(2) to sigaction(2) and sets SA_RESTART?