<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 01 Jun 2013, at 08:51, Dennis Poon wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">
<div bgcolor="#ffffff" text="#000000">
<font size="+1">Ewald,<br>
<br>
Please kindly share your sample codes for both approaches.<br>
Thanks a lot<br></font></div></blockquote><br></div><div>Right, here you go:</div><div><br></div><div>*** fpSignal() ***</div><div>First you declare a function which is going to handle the signal (SignalHandler in my example), then you just call </div><div><span class="Apple-tab-span" style="white-space:pre"> </span>fpSignal(SIGPIPE, @SignalHandler);</div><div> </div><div>An example program:</div><div><br></div><div>===code begin===</div><div>Program SignalTest;</div><div><br></div><div>Uses sysutils, baseunix;</div><div><br></div><div><div>Procedure SignalHandler(SigNo: cint); cdecl;</div><div>Begin</div><div> If SigNo = SIGPIPE Then WriteLn('Received SIGPIPE.');</div><div>End;</div><div><br></div><div>Begin</div><div><span class="Apple-tab-span" style="white-space:pre"> fpSignal(SIGPIPE, @SignalHandler);</span></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>while true do sleep(5000);</div><div>End.</div><div>===code end===</div><div><br></div><div>Compile using `fpc SignalTest.pas`. Whilst running it, try sending SIGPIPE to it (`killall -PIPE SignalTest`) and it should write something to stdout.</div></div><div><br></div><div><br></div><div>***pthread_sigmask()***</div><div><div><br></div><div>It basically comes down to:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>- Emtying a signal set</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>- Adding the signals you wish to block</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>- Calling pthread_sigmask with this set and SIG_BLOCK as arguments.</div><div><br></div><div>And example program:</div><div><br></div><div>===code begin===</div><div><div>Program SigmaskTest;</div><div><br></div><div>Uses sysutils, baseunix, pthreads;</div><div><br></div><div>Var</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ToBeBlocked: sigset_t;</div><div>Begin</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>fpSigEmptySet(ToBeBlocked);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>fpsigaddset(ToBeBlocked, SIGPIPE);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>pthread_sigmask(SIG_BLOCK, @ToBeBlocked, nil);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>while true do sleep(5000);</div><div>End.</div><div>===code end===</div></div></div><div><br></div><div>Compile using `fpc SigmaskTest.pas`. Whilst running it, try sending SIGPIPE to it (`killall -PIPE SigmaskTest `) and it should continue running.</div><div><br></div><div>NOTE: this function will need to be called by each thread that wishes to block this signal, except in the case where the parent thread already has this signal blocked, as newly created threads inherit their parents sigmask (according to <a href="http://linux.die.net/man/3/pthread_sigmask">http://linux.die.net/man/3/pthread_sigmask</a>)</div><div><br></div><div>Hope it helps! </div><br><div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div style="font-size: medium; color: rgb(0, 0, 0); font-style: normal; ">--</div><div style="font-size: medium; color: rgb(0, 0, 0); font-style: normal; ">Ewald</div></div></div></div></div>
</div>
<br></body></html>