Sponsored Content
Top Forums Programming Catch signal SIGPIPE print errno but it's value equal to 2 Post 302412431 by achenle on Monday 12th of April 2010 01:26:17 PM
Old 04-12-2010
Quote:
Originally Posted by Corona688
I suppose errno's just not being set until the signal handler returns, then. Which makes sense when I think about it since the system call getting SIGPIPE hasn't returned yet either! Smilie

Never call printf in a signal handler by the way, it's not signal-safe. This means it will work much of the time but will crash in odd unpredictable circumstances for no reason your debugger will be able to guess. fprintf(stderr, "..."); is nonbuffered, hence a bit safer, but still not guaranteed! Use lower system calls like write().
Actually, to be (overly?) pedantic, it almost certainly won't crash but it will deadlock your app if the signal is delivered to a thread that holds any lock that the printf() call might need, such as for heap allocations, which printf() tends to do.

And fprintf( stderr, ... ) is just as likely to need those locks, so it's not any safer.

Although for practical purposes, in this case it's pretty difficult to get a SIGFPE delivered to a thread that's already deep in libc doing things like malloc() or free().
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

catch SIGCHLD signal in parent process

I want to catch SIGCHLD signal in parent process. I can't use wait() system call to catch SIGCHLD according to project requirment. Operating system linux 3.1 can any one have a solution for this. Thanking you, ranjan (2 Replies)
Discussion started by: ranjan
2 Replies

2. AIX

auditing fails with SIGPIPE signal on 1/4 hour

Hi folks, Can anyone assist with pointers for the following snag? We have custom method (IBM-supplied) for running the audit subsystem on 5.1-07 /etc/security/audit objects, events and config have been edited, and the /etc/security/audit/streamcmds contains the following routine; ... (1 Reply)
Discussion started by: reclspeak
1 Replies

3. Shell Programming and Scripting

Threshold is less than 0.003 or equal then print the line

Friends, I have very large data files (File1 and File2). Search field1 of File1 into Field1 of File2. If found then do Field1 of File1 MINUS Field1 of File2 if the answer is <= 0.003 (positive or negative) then print that line from File1. File1 ABC1231|1.1111|2.2122|3.3133... (3 Replies)
Discussion started by: ppat7046
3 Replies

4. Programming

Reliable management of signal SIGPIPE and SIGTERM

I' m note very expert in the reliable manage of signal... but in my server I must manage SIGPIPE for the socket and SIGTERM... I've wrote this but there is something wrong... Can someone explain me with some example the reliable management of signal?? This is what I've wrote in the server ... (2 Replies)
Discussion started by: italian_boy
2 Replies

5. UNIX for Advanced & Expert Users

Why not SIGPIPE for readers of pipe/FIFO?

Hi This is a exercise question from Unix network programming vol2. Why the SIGPIPE signal is generated only for writers when readers disappear. why not it is generated for readers when writer disappears. I guess, if the writer didn't get any response like the reader gets EOF, it will... (4 Replies)
Discussion started by: kumaran_5555
4 Replies

6. Shell Programming and Scripting

Using awk, print all the lines where field 8 is equal to x

Using awk, print all the lines where field 8 is equal to x I really did try, but this awk thing is really hard to figure out. file1.txt"Georgia","Atlanta","2011-11-02","x","","","","" "California","Los Angeles","2011-11-03","x","","","",""... (2 Replies)
Discussion started by: charles33
2 Replies

7. Programming

SIGPIPE and EPIPE

When a write() writes on a broken pipe, with no readers, it generates a SIGPIPE signal and the process exits. When the write() returns -1 and errno is EPIPE? Do I have an handler for SIGPIPE, or can I ignore it? (2 Replies)
Discussion started by: hurricane
2 Replies

8. Shell Programming and Scripting

awk to print record not equal specific pattern

how to use "awk" to print any record has pattern not equal ? for example my file has 5 records & I need to get all lines which $1=10 or 20 , $2=10 or 20 and $3 greater than "130302" as it shown : 10 20 1303252348212B030 20 10 1303242348212B030 40 34 1303252348212B030 10 20 ... (14 Replies)
Discussion started by: arm
14 Replies

9. Shell Programming and Scripting

If first character doesn't equal '#' and same line contains 'temp', print everything else

(2 Replies)
Discussion started by: snoman1
2 Replies

10. Shell Programming and Scripting

How to print out with equal spacing between columns?

For instance, my file contains the following content... set -A array set -A test ${array}=1 ${array}=2 ${array}=3 ${test}="Boy" ${test}="Girl" ${test}="Dog" x=0 while ;do print "${array}" " " "${test}" x=$((x+1) done... (1 Reply)
Discussion started by: TestKing
1 Replies
pthread_rwlock_timedrdlock(3C)				   Standard C Library Functions 			    pthread_rwlock_timedrdlock(3C)

NAME
pthread_rwlock_timedrdlock, pthread_rwlock_reltimedrdlock_np - lock a read-write lock for reading SYNOPSIS
cc -mt [ flag... ] file... [ library... ] #include <pthread.h> #include <time.h> int pthread_rwlock_timedrdlock(pthread_rwlock_t *restrict rwlock, const struct timespec *restrict abs_timeout); int pthread_rwlock_reltimedrdlock_np(pthread_rwlock_t *restrict rwlock, const struct timespec *restrict rel_timeout); DESCRIPTION
The pthread_rwlock_timedrdlock() function applies a read lock to the read-write lock referenced by rwlock as in the pthread_rwlock_rdlock(3C) function. If the lock cannot be acquired without waiting for other threads to unlock the lock, this wait will be terminated when the specified timeout expires. The timeout expires when the absolute time specified by abs_timeout passes, as measured by the CLOCK_REALTIME clock (that is, when the value of that clock equals or exceeds abs_timeout), or if the absolute time specified by abs_timeout has already been passed at the time of the call. The pthread_rwlock_reltimedrdlock_np() function is identical to the pthread_rwlock_timedrdlock() function, except that the timeout is spec- ified as a relative time interval. The timeout expires when the time interval specified by rel_timeout passes, as measured by the CLOCK_REALTIME clock, or if the time interval specified by rel_timeout is negative at the time of the call. The resolution of the timeout is the resolution of the CLOCK_REALTIME clock. The timespec data type is defined in the <time.h> header. Under no circumstances does either function fail with a timeout if the lock can be acquired immediately. The validity of the timeout param- eter need not be checked if the lock can be immediately acquired. If a signal that causes a signal handler to be executed is delivered to a thread blocked on a read-write lock with a call to pthread_rwlock_timedrdlock() or pthread_rwlock_reltimedrdlock_np(), upon return from the signal handler the thread resumes waiting for the lock as if it was not interrupted. The calling thread might deadlock if at the time the call is made it holds a write lock on rwlock. The results are undefined if this function is called with an uninitialized read-write lock. RETURN VALUES
The pthread_rwlock_timedrdlock() and pthread_rwlock_reltimedrdlock_np() functions return 0 if the lock for reading on the read-write lock object referenced by rwlock is acquired. Otherwise, an error number is returned to indicate the error. ERRORS
The pthread_rwlock_timedrdlock() and and pthread_rwlock_reltimedrdlock_np() functions will fail if: ETIMEDOUT The lock could not be acquired before the specified timeout expired. The pthread_rwlock_timedrdlock() and pthread_rwlock_reltimedrdlock_np() functions may fail if: EAGAIN The read lock could not be acquired because the maximum number of read locks for lock would be exceeded. EDEADLK The calling thread already holds a write lock on rwlock. EINVAL The value specified by rwlock does not refer to an initialized read-write lock object, or the timeout nanosecond value is less than zero or greater than or equal to 1 000 million. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |See below. | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ The pthread_rwlock_timedrdlock() function is Standard. The pthread_rwlock_reltimedrdlock_np() is Stable. SEE ALSO
pthread_rwlock_destroy(3C), pthread_rwlock_rdlock(3C), pthread_rwlock_timedwrlock(3C), pthread_rwlock_trywrlock(3C), pthread_rwlock_unlock(3C), pthread_rwlock_wrlock(3C), attributes(5), standards(5) SunOS 5.11 30 Jan 2004 pthread_rwlock_timedrdlock(3C)
All times are GMT -4. The time now is 08:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy