Catch signal SIGPIPE print errno but it's value equal to 2


 
Thread Tools Search this Thread
Top Forums Programming Catch signal SIGPIPE print errno but it's value equal to 2
# 8  
Old 04-19-2010
Quote:
Originally Posted by Corona688
So it's nothing to do with the file-handles, and everything to do with memory allocation? That's unfortunate. You couldn't even call sprintf then...
The problem with heap memory allocation is locks - if the thread the signal is delivered to holds a lock on the heap inside a call to malloc() or free(), for example, the thread will deadlock if the signal handler attempts to acquire that lock.

And that problem is more likely to happen than you might think. Way too many programmers overuse malloc/free and new/delete, effectively single-threading multithreaded applications through the heap. It's not uncommon to get a stack trace for a multithreaded application and see, for example, 45 of its 50 threads all waiting for the same mutex that the malloc() implementation uses. In an app like that, any signal handler that indirectly uses the heap is very likely to deadlock. (Offhand, I think that's because OS's tend to deliver signals to threads that are already running if not the very thread that triggered the signal, and in an app like that most of the threads are sleeping waiting for the heap mutex. Also, in apps like that with massive heap use, the most likely signal is a SEGV to a thread doing heap manipulation in malloc() or free() and therefore already holding the heap lock.)

And there are probably other issues with async-signal safety besides locks, but off the top of my head I can't think of any.

FWIW, on Solaris sprintf() and snprintf() are async-signal-safe. Linux man pages don't specify async-signal safety.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question