Sponsored Content
Top Forums Programming using signals instead of busy wait Post 302146519 by porter on Wednesday 21st of November 2007 02:48:25 AM
Old 11-21-2007
Quote:
Originally Posted by jut26
I am looking for some examples of c programs which use a signal to notify the program to begin a certain action instead of having it continually loop to check to see if condition is attained
I suggest a program based around select and have a pipe pair dedicated to supporting signals. The write end is written by the signal handle (write a single byte containing the number of the signal) and have the select include the read end of the pipe in the read fd_set.

Then when a signal occurs a single byte is written to the pipe, this wakes up the select, the code in the select loop then reads the pipe and knows which signal occurred and can then handle it in a more graceful manner.
 

5 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

CD Drive is busy

one problem which seems simple but i've faced many times is when i've used cd & want to eject, however i'm not in /dev/cdrom/... in any of my Xterms but it gives the message that the the CD drive is busy. the only thing i could do is /etc/init.d/volmgt stop & eject the CD manually but it doesn't... (6 Replies)
Discussion started by: nikk
6 Replies

2. Shell Programming and Scripting

Need to execute 2 scripts, wait, execute 2 more wait, till end of file

:cool: I need to execute a shell script to do the following: cat a file run two back ground processes using the first two values from the file wait till those background processes finish run two more background processes using the next two values from the file wait till those background... (1 Reply)
Discussion started by: halo98
1 Replies

3. Shell Programming and Scripting

wait command - cat it wait for not-chile process?

Did not use 'wait' yet. How I understand by now the wait works only for child processes, started background. Is there any other way to watch completion of any, not related process (at least, a process, owned by the same user?) I need to start a background process, witch will be waiting... (2 Replies)
Discussion started by: alex_5161
2 Replies

4. UNIX for Advanced & Expert Users

Filesystem mystery: disks are not busy on one machine, very busy on a similar box

Hi, We have a filesystem mystery on our hands. Given: 2 machines, A and Aa. Machine Aa is the problem machine. Machine A is running Ubuntu, kernel 2.6.22.9 #1 SMP Wed Feb 20 08:46:16 CST 2008 x86_64 GNU/Linux. Machine Aa is running RHEL5.3, kernel 2.6.18-128.el5 #1 SMP Wed Dec 17 11:41:38... (2 Replies)
Discussion started by: mschwage
2 Replies

5. Shell Programming and Scripting

calling a shell script in background and wait using "wait" in while loop

Hi, I am facing a strange issue, when i call a script from my while loop in background it doesnt go in background, despite the wait i put below the whil loop it goes forward even before the process put in background is completed. cat abc.txt | while read -u4 line do #if line contains #... (2 Replies)
Discussion started by: mihirvora16
2 Replies
PIPE(2) 						      BSD System Calls Manual							   PIPE(2)

NAME
pipe -- create descriptor pair for interprocess communication LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <unistd.h> int pipe(int fildes[2]); int pipe2(int fildes[2], int flags); DESCRIPTION
The pipe() function creates a pipe, which is an object allowing unidirectional data flow, and allocates a pair of file descriptors. The first descriptor connects to the read end of the pipe, and the second connects to the write end, so that data written to fildes[1] appears on (i.e., can be read from) fildes[0]. This allows the output of one program to be sent to another program: the source's standard output is set up to be the write end of the pipe, and the sink's standard input is set up to be the read end of the pipe. The pipe itself persists until all its associated descriptors are closed. A pipe whose read or write end has been closed is considered widowed. Writing on such a pipe causes the writing process to receive a SIGPIPE signal. Widowing a pipe is the only way to deliver end-of-file to a reader: after the reader consumes any buffered data, reading a widowed pipe returns a zero count. The pipe2() function behaves exactly like pipe() only it allows extra flags to be set on the returned file descriptor. The following flags are valid: O_CLOEXEC Set the ``close-on-exec'' property. O_NONBLOCK Sets non-blocking I/O. O_NOSIGPIPE Return EPIPE instead of raising SIGPIPE. RETURN VALUES
On successful creation of the pipe, zero is returned. Otherwise, a value of -1 is returned and the variable errno set to indicate the error. ERRORS
The pipe() and pipe2() calls will fail if: [EFAULT] The fildes buffer is in an invalid area of the process's address space. The reliable detection of this error cannot be guaranteed; when not detected, a signal may be delivered to the process, indicating an address violation. [EMFILE] Too many descriptors are active. [ENFILE] The system file table is full. pipe2() will also fail if: [EINVAL] flags is other than O_NONBLOCK or O_CLOEXEC. SEE ALSO
sh(1), fork(2), read(2), socketpair(2), write(2) STANDARDS
The pipe() function conforms to ISO/IEC 9945-1:1990 (``POSIX.1''). HISTORY
A pipe() function call appeared in Version 6 AT&T UNIX. The pipe2() function is inspired from Linux and appeared in NetBSD 6.0. BSD
January 23, 2012 BSD
All times are GMT -4. The time now is 04:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy