Using the Gnu alarm function to interrupt the program

D

dutche

I'm using the alarm function to wake up every 60 seconds and execute
some function I choose.
It's fine, and working.
The problem is that sometimes, when the alarm wake up, it interrupts
some running function in the middle of process, and this is not the
behavior I want.

I want to make the running function uninterrupable and then, when it
terminates, the alarm function can execute.

How could I do that? Any ideas?? Thanks
 
A

arus

I'm using the alarm function to wake up every 60 seconds and execute
some function I choose.
It's fine, and working.
The problem is that sometimes, when the alarm wake up, it interrupts
some running function in the middle of process, and this is not the
behavior I want.

I want to make the running function uninterrupable and then, when it
terminates, the alarm function can execute.

How could I do that? Any ideas?? Thanks
If I understand your question correctly what
you are looking for is to "block" the interrupts.
You can do that using sigprocmask
http://www.gnu.org/s/libc/manual/html_node/Process-Signal-Mask.html
 
K

Keith Thompson

dutche said:
I'm using the alarm function to wake up every 60 seconds and execute
some function I choose.
It's fine, and working.
The problem is that sometimes, when the alarm wake up, it interrupts
some running function in the middle of process, and this is not the
behavior I want.

I want to make the running function uninterrupable and then, when it
terminates, the alarm function can execute.

How could I do that? Any ideas?? Thanks

The alarm function isn't GNU-specific; it's specified by POSIX.

The best place to ask about it is comp.unix.programmer.
 
R

Ralph Malph

The alarm function isn't GNU-specific; it's specified by POSIX.

The best place to ask about it is comp.unix.programmer.
Why would you say that? He got a more or less correct response
within 20 minutes by posting to c.l.c!
By any practical measurement c.l.c was the best place to ask!
 
E

Eric Sosman

Why would you say that? He got a more or less correct response
within 20 minutes by posting to c.l.c!
By any practical measurement c.l.c was the best place to ask!

It's the "or less" that makes the difference. Here in c.l.c.
he was told about sigprocmask() -- but there's a whole lot more he
needs to know about POSIX signals than is contained in the response
he got, or even in the document it linked to! The folks in c.u.p.
will know those other things and will be able to offer help with
them; here in c.l.c. all he can count on is more "or less" than
what he needs.
 
K

Keith Thompson

Ralph Malph said:
On 4/28/2010 2:09 PM, Keith Thompson wrote: [...]
The alarm function isn't GNU-specific; it's specified by POSIX.

The best place to ask about it is comp.unix.programmer.
Why would you say that? He got a more or less correct response
within 20 minutes by posting to c.l.c!

Because it's true. The response he got may well have been correct,
but c.u.p has more readers who are able to confirm (or deny)
its correctness. I've seen plenty of incorrect system-specific
responses here, some of which have been corrected only by luck.
By any practical measurement c.l.c was the best place to ask!

Did you do a comparison? How long would it have taken him to get a
correct answer if he'd posted in comp.unix.programmer?
 
R

Ralph Malph

Keith said:
Ralph Malph said:
On 4/28/2010 2:09 PM, Keith Thompson wrote: [...]
The alarm function isn't GNU-specific; it's specified by POSIX.

The best place to ask about it is comp.unix.programmer.
Why would you say that? He got a more or less correct response
within 20 minutes by posting to c.l.c!

Because it's true. The response he got may well have been correct,
but c.u.p has more readers who are able to confirm (or deny)
its correctness. I've seen plenty of incorrect system-specific
responses here, some of which have been corrected only by luck.
By any practical measurement c.l.c was the best place to ask!

Did you do a comparison? How long would it have taken him to get a
correct answer if he'd posted in comp.unix.programmer?
Wow, you really are retarded in most aspects of life aren't you?
The response provided was fine. c.u.p. wouldn't be any better.
While you and Seebs are prone to long asperger's fueled screeds
most people would care to just receive a nice accurate response rather
than some "non-portable since on Xenix|AIX|Obscur-ix it was not
implemented!" bullshit.
**** Off And Die
 
W

William Hughes

c.u.p. wouldn't be any better.

You do not seem to get the point.
The reply may have been fine as far
as it went (it did not go very far) but
this is not the correct forum to decide that.
There are a lot more experts to judge
the correctness and completeness of results
on c.u.p.

Basically you were wrong, and now you are flailing
and posting insults. Grow up.

- William Hughes
 
K

Kenny McCormack

Ralph Malph said:
Wow, you really are retarded in most aspects of life aren't you?
The response provided was fine. c.u.p. wouldn't be any better.
While you and Seebs are prone to long asperger's fueled screeds
most people would care to just receive a nice accurate response rather
than some "non-portable since on Xenix|AIX|Obscur-ix it was not
implemented!" bullshit.
**** Off And Die

Congratulations. You've got Kiki's # down to a T. He really is
retarded in any kind of social sense.

Others (such as little billy hughes) will come along with a bunch of
dumb analogies (like: I'm driving down the street in my car and I see a
bicylist doing cartwheels. Therefore, Kiki is right). Just ignore them.

--
(This discussion group is about C, ...)

Wrong. It is only OCCASIONALLY a discussion group
about C; mostly, like most "discussion" groups, it is
off-topic Rorsharch [sic] revelations of the childhood
traumas of the participants...
 
P

Phil Carmody

William Ahern said:
What if somebody asked a Latin grammar question here

Well, Latin having a subjunctive mood, it would be better to avoid
the imperative, and favour "Were someone to ask ..." instead.

And better for me to plonk whoever he is.

Phil
 
R

Ralph Malph

Kenny said:
Congratulations. You've got Kiki's # down to a T. He really is
retarded in any kind of social sense.

Others (such as little billy hughes) will come along with a bunch of
dumb analogies (like: I'm driving down the street in my car and I see a
bicylist doing cartwheels. Therefore, Kiki is right). Just ignore them.
It is just weird the lengths some people go to
not help people and obfuscate easy issues.
I swear some of these clowns have day jobs at the post
office or DMV!
 
N

Nobody

I'm using the alarm function to wake up every 60 seconds and execute
some function I choose.
It's fine, and working.
The problem is that sometimes, when the alarm wake up, it interrupts
some running function in the middle of process, and this is not the
behavior I want.

I want to make the running function uninterrupable and then, when it
terminates, the alarm function can execute.

How could I do that? Any ideas?? Thanks

Why are you using alarm() if you don't want it to interrupt a function?

If you just want to sleep for a certain amount of time, use sleep(),
usleep() or nanosleep().

If you normally want it to interrupt execution but prevent this in
specific cases, use sigprocmask() as suggested by arus.

If you want it to interrupt user functions but not system calls, install
the handler using sigaction() and the SA_RESTART flag.
 
K

Kenny McCormack

Ralph Malph said:
It is just weird the lengths some people go to
not help people and obfuscate easy issues.

Yup. That's the game.
I swear some of these clowns have day jobs at the post
office or DMV!

So true. So true.

--
(This discussion group is about C, ...)

Wrong. It is only OCCASIONALLY a discussion group
about C; mostly, like most "discussion" groups, it is
off-topic Rorsharch [sic] revelations of the childhood
traumas of the participants...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top