Sponsored Content
Top Forums Programming Reliable management of signal SIGPIPE and SIGTERM Post 302406362 by Loic Domaigne on Monday 22nd of March 2010 04:45:50 PM
Old 03-22-2010
Quote:
Originally Posted by italian_boy
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??
You should proceed as follows:
  • for SIGPIPE: you usually want to set to ignore SIGPIPE. Advantage: you will be synchronously informed in the send() function if a SIGPIPE is caught (return -1, and errno is set to EPIPE). No need to mess up with a signal handler.
  • for SIGTERM, set simply a signal handler with sigaction()

This simply looks like this:
Code:
struct sigaction act;

// ignore SIGPIPE
act.sa_handler=SIG_IGN;
sigemptyset(&act.sa_mask);
act.sa_flags=0;
sigaction(SIGPIPE, &act, NULL); 

// set my handler for SIGTERM
act.sa_handler=catcher;
sigemptyset(&act.sa_mask);
act.sa_flags=0;
sigaction(SIGTERM, &act, NULL);

In particular, don't use sigprocmask. You would block the signal SIGTERM and SIGPIPE, preventing effectively your handlers to run!

HTH,
Loïc.
 

9 More Discussions You Might Find Interesting

1. Programming

signals - SIGTERM

Hi all, I need some urgent help. we are using Dynix/ptx V4.5 on i386, have several processes and instances are running on the box round the clock.we increased the processes recently. We have coded to handle the signals in our programs. Recently, we noticed most of our processes are... (2 Replies)
Discussion started by: reddyb
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

How to detect SIGTERM,SIGKILL signal in UNIX

Dear All We have JBOSS server running on Linux we need to track Graceful Shutdown(SIGTERM) and Forceful Shutdown(SIGKILL) timestamp and write it into one file, I am new to UNIX Signal processing if is it possible how to detect it? We generally do $kill PID For Graceful... (5 Replies)
Discussion started by: mnmonu
5 Replies

4. Programming

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

catch signal SIGPIPE ,print errno but it's value equal to 2(ENOENT) #define ENOENT 2 /* No such file or directory */ is it should be EPIPE ? #define EPIPE 32 /* Broken pipe */ Thanks ! (7 Replies)
Discussion started by: aobai
7 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. 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

7. UNIX for Dummies Questions & Answers

Is this website reliable ?

edit by bakunin: content not relevant for our site (and bordering on spam) SNIPped, thread closed. My suggestion is to - before even considering to buy anything online - put more effort in research, i.e. what the web site you write a comment at, is all about. This one here is definitely not for... (1 Reply)
Discussion started by: ethansk
1 Replies

8. Homework & Coursework Questions

C TCP/IP Reliable Transmission project not reliable

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: We must do the following for a massive coding project that is due at 12:20PM on Monday, July 22, 2013. We are to... (1 Reply)
Discussion started by: kowit010
1 Replies

9. AIX

SIGTERM failing in AIX

I have 2 AIX 6.1 systems running on PowerPCs - production and .. .everything else. :p . Until the installation of a TLS certificate in an application, some copying of files ("cloning an environment") and upgrading a listener, sending a kill -15 worked on any script/application, so long as we were... (6 Replies)
Discussion started by: Mrucker
6 Replies
siginterrupt(3C)					   Standard C Library Functions 					  siginterrupt(3C)

NAME
siginterrupt - allow signals to interrupt functions SYNOPSIS
#include <signal.h> int siginterrupt(int sig, int flag); DESCRIPTION
The siginterrupt() function changes the restart behavior when a function is interrupted by the specified signal. The function siginter- rupt(sig, flag) has an effect as if implemented as: siginterrupt(int sig, int flag) { int ret; struct sigaction act; (void) sigaction(sig, NULL, &act); if (flag) act.sa_flags &= SA_RESTART; else act.sa_flags |= SA_RESTART; ret = sigaction(sig, &act, NULL); return ret; } RETURN VALUES
Upon successful completion, siginterrupt() returns 0. Otherwise, -1 is returned and errno is set to indicate the error. ERRORS
The siginterrupt() function will fail if: EINVAL The sig argument is not a valid signal number. USAGE
The siginterrupt() function supports programs written to historical system interfaces. A standard-conforming application, when being writ- ten or rewritten, should use sigaction(2) with the SA_RESTART flag instead of siginterrupt(). ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
sigaction(2), signal.h(3HEAD), attributes(5), standards(5) SunOS 5.10 1 Sep 2003 siginterrupt(3C)
All times are GMT -4. The time now is 07:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy