Sponsored Content
Top Forums Programming How to sleep and wake a thread??? Post 302582653 by DreamWarrior on Friday 16th of December 2011 05:15:44 PM
Old 12-16-2011
Quote:
Originally Posted by Corona688
Interesting. That'll take some careful use of signals though, whether a system call returns with SIGINT when interrupted is optional, and not all systems have the same default.
That's why you use sigaction; if you want the system call to restart after signal then supply the SA_RESTART flag, otherwise, don't and you'll get SIGINT. While the default behavior may be different across systems, sigaction insures you get the behavior you want. This is why sigaction is preferred over signal for portable code.

edit: as an aside, when we ported a large system from HP-UX to Linux this was a big problem. The team doing the port didn't understand signals very well in general, and the default behavior of a handler installed with signal in HP-UX is different from Linux. They had lots of issues, and I had to explain quite a bit to them to get things working right. Linux was also a lot less forgiving of their dumb use of sigblock and sigunblock to "protect" them from reentering a signal handler. This stupidity caused some very interesting stack traces until I explained the right way to do it was to provide the correct signal mask to sigaction so the block/unblock would occur atomically with the calling of the signal.... Ahh...good times with less than stellar developers, lol.
Quote:
Originally Posted by Corona688
Maybe not on your system, but some sure do.
I suppose the man page for sleep does mention SIGALRM may be used to implement sleep, but have you seen one actually do it?

Last edited by DreamWarrior; 12-16-2011 at 06:21 PM..
 

7 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Wake on Lan script

Im old to Unix but new to scripting I have a MacBook running osx that I want to use as an nfs client. The server will be a linux box with a wake on lan card. Here's the idea. Run a cron command on the mac every minute that checks if I am on my home wireless network (the linux box is wired to... (0 Replies)
Discussion started by: anon0mus
0 Replies

2. Shell Programming and Scripting

Wake on LAN script

m old to Unix but new to scripting I have a MacBook running osx that I want to use as an nfs client. The server will be a linux box with a wake on lan card. Here's the idea. Run a cron command on the mac every minute that checks if I am on my home wireless network (the linux box is wired to... (6 Replies)
Discussion started by: anon0mus
6 Replies

3. Programming

how to wake up a thread that blocking at epoll_wait?

I have two threads: one maintains a thread-safe message queue (handle this queue at the beginning of every loop) and deals with tcp connections, the other one posts message to the former one. the problem is, while the former one was blocking at epoll_wait, it's not sure that how long until the... (0 Replies)
Discussion started by: cometeor
0 Replies

4. UNIX for Advanced & Expert Users

wake up user space thread from kernel space ISR

Hello, I'm searching for a proper way to let the kernel space ISR(implemented in a kernel module) wake up a user space thread on a hardware interrupt. Except for sending a real-time signal, is it possible to use a semaphore? I've searched it on google, but it seems impossible to share a... (0 Replies)
Discussion started by: aaronwong
0 Replies

5. Shell Programming and Scripting

Wrapping 'sleep' with my 'resleep' function (Resettable sleep)

This is a very crude attempt in Bash at something that I needed but didn't seem to find in the 'sleep' command. However, I would like to be able to do it without the need for the temp file. Please go easy on me if this is already possible in some other way: How many times have you used the... (5 Replies)
Discussion started by: deckard
5 Replies

6. UNIX for Dummies Questions & Answers

Linux Device Driver: how can an ISR wake up a user-thread?

Hi all, Is it possible to do the following in Linux (kernel 2.6.x): - A user-space thread goes to "sleep". Using any call/mechanism - On a hardware generated interrupt, the Interrupt handler (ISR) "wakes" the sleeping user-thread. I have seen wait_event() and wake_up() but it appears... (1 Reply)
Discussion started by: agaurav
1 Replies

7. UNIX for Dummies Questions & Answers

Computer wake commands

I'm a OS X user (MacBook Pro, OS X Lion) and I need it to wake up on Mondays, Wednesdays, Thursdays and Saturdays at 9:00 AM on the rest of the days of the week at 7:00 I issue the following commands: sudo pmset repeat wake MWRS 09:00:00 for the former sudo pmset repeat wake TFU... (1 Reply)
Discussion started by: scrutinizerix
1 Replies
SIGINTERRUPT(3) 					   BSD Library Functions Manual 					   SIGINTERRUPT(3)

NAME
siginterrupt -- allow signals to interrupt system calls LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <signal.h> int siginterrupt(int sig, int flag); DESCRIPTION
The siginterrupt() function is used to change the system call restart behavior when a system call is interrupted by the specified signal. If the flag is false (0), then system calls will be restarted if they are interrupted by the specified signal and no data has been transferred yet. System call restart is the default behavior on 4.2BSD. If the flag is true (1), then restarting of system calls is disabled. If a system call is interrupted by the specified signal and no data has been transferred, the system call will return -1 with the global variable errno set to EINTR. Interrupted system calls that have started transferring data will return the amount of data actually transferred. System call interrupt is the signal behavior found on 4.1BSD and AT&T System V UNIX systems. Note that the new 4.2BSD signal handling semantics are not altered in any other way. Most notably, signal handlers always remain installed until explicitly changed by a subsequent sigaction(2) call, and the signal mask operates as documented in sigaction(2). Programs may switch between restartable and interruptible system call operation as often as desired in the execution of a program. Issuing a siginterrupt(3) call during the execution of a signal handler will cause the new action to take place on the next signal to be caught. NOTES
This library routine uses an extension of the sigaction(2) system call that is not available in 4.2BSD, hence it should not be used if back- ward compatibility is needed. RETURN VALUES
A 0 value indicates that the call succeeded. A -1 value indicates that an invalid signal number has been supplied. SEE ALSO
sigaction(2), sigprocmask(2), sigsuspend(2) HISTORY
The siginterrupt() function appeared in 4.3BSD. BSD
June 4, 1993 BSD
All times are GMT -4. The time now is 01:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy