On 01 Jun 2013, at 08:51, Dennis Poon wrote: > Ewald, > > Please kindly share your sample codes for both approaches. > Thanks a lot
Right, here you go: *** fpSignal() *** First you declare a function which is going to handle the signal (SignalHandler in my example), then you just call fpSignal(SIGPIPE, @SignalHandler); An example program: ===code begin=== Program SignalTest; Uses sysutils, baseunix; Procedure SignalHandler(SigNo: cint); cdecl; Begin If SigNo = SIGPIPE Then WriteLn('Received SIGPIPE.'); End; Begin fpSignal(SIGPIPE, @SignalHandler); while true do sleep(5000); End. ===code end=== Compile using `fpc SignalTest.pas`. Whilst running it, try sending SIGPIPE to it (`killall -PIPE SignalTest`) and it should write something to stdout. ***pthread_sigmask()*** It basically comes down to: - Emtying a signal set - Adding the signals you wish to block - Calling pthread_sigmask with this set and SIG_BLOCK as arguments. And example program: ===code begin=== Program SigmaskTest; Uses sysutils, baseunix, pthreads; Var ToBeBlocked: sigset_t; Begin fpSigEmptySet(ToBeBlocked); fpsigaddset(ToBeBlocked, SIGPIPE); pthread_sigmask(SIG_BLOCK, @ToBeBlocked, nil); while true do sleep(5000); End. ===code end=== Compile using `fpc SigmaskTest.pas`. Whilst running it, try sending SIGPIPE to it (`killall -PIPE SigmaskTest `) and it should continue running. 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 http://linux.die.net/man/3/pthread_sigmask) Hope it helps! -- Ewald
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal