duckvader duckvader - 1 year ago 75
C Question

Issues with using ualarm

In my code, i need to call sigalrm after 2 seconds. However, when i use

ualarm(2000000, 0 )
it doesn't work. using
less than 1 second works. Whereas
works. Is there a reason why
should be used at times over
? Is there any way to get
to work for over 1 second?

Answer Source

ualarm() is obsolete, and in fact has been removed from POSIX. Do not use it.

If you insist on using it anyway, the Linux manual page for it notes this:

The type useconds_t is an unsigned integer type capable of holding integers in the range [0,1000000].

, which I guess is a reference to the one-time POSIX specification. What you should take from that is that POSIX ualarm() was never guaranteed to be able to handle a first argument larger than 1000000. It's unclear whether any implementations ever did handle larger values, but the fact that POSIX specified it as it did suggests that at least some implementations did not.

Is there any way to get ualarm to work for over 1 second?

Since there is not (any longer) any standard for ualarm(), the answer is necessarily implementation-dependent. Based on what you presented, I'm inclined to think that with your implementation, the answer is "no".