Sponsored Content
Full Discussion: bash dropping SIGHUPs
Top Forums Shell Programming and Scripting bash dropping SIGHUPs Post 302548448 by cambridge on Thursday 18th of August 2011 11:50:40 AM
Old 08-18-2011
bash dropping SIGHUPs

I've written a daemon in bash, that waits for a HUP signal and then does some processing, before waiting for the next HUP. It goes something like this:
Code:
trap gothup=1 HUP
while :; do
    gothup=0

    # do some processing ...

    # now wait for a HUP ...
    while [ $gothup -eq 0 ]; do
        sleep 30 &
        wpid=$!

        if [ $gothup -eq 0 ]; then
            wait $wpid
            [ $? -lt 128 ] && continue
        fi

        # kill $wpid if still running ...

    done
done

I couldn't figure out a way to get bash to store up signals during a critical piece of code. The above was the best I could get, but my concern is, what if I receive a HUP *after* this test:
Code:
        if [ $gothup -eq 0 ]; then

but before the next instruction:
Code:
            wait $wpid

In that scenario, the wait will block for 30 seconds or until another HUP is received, i.e. it would have missed one HUP.

How can I improve this so there's no chance of missing a HUP?

Thanks,
Mark.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

strintercept dropping message on unixware

i have unixware 2.1. A warning message Strintercept dropping message start scrolling on screen. does anyone have any idea what it means? :confused: and some times system hangs with all terminals.? (2 Replies)
Discussion started by: kapilverma_udr
2 Replies

2. Shell Programming and Scripting

Sed command dropping last record in File

Hello: I wrote a sed statement that is inserting 3 variables at the beginning of each record in a comma-delimited file: for FILE in *gnrc_lkup.csv do c=`echo $FILE | cut -c1-3` d=`grep $c $RTLIST | cut -c4-6` e=`grep $c $RTLIST | cut -c7` f=`grep $c $RTLIST | cut -c8` sed -e... (5 Replies)
Discussion started by: bheeke
5 Replies

3. Linux

Free Linux Memory by Dropping Caches

Linux Kernels 2.6.16 and up provide a way to instruct the kernel to drop the page cache, inode and dentry caches on command. This tip can help free Linux memory without a reboot. Note: This is a non-destructive operation. Dirty objects are not freeable, hence; you must run sync beforehand. ... (0 Replies)
Discussion started by: Neo
0 Replies

4. Shell Programming and Scripting

Dropping Records for unknown reason in awk script

Hi, I have written the following it is pretty sloppy but I don't see any reason why I should be losing 54 records from a 3.5 million line file after using it. What I am doing: I have a 3.5 million record file with about 80,000 records need a correction. They are missing the last data from... (8 Replies)
Discussion started by: mkastin
8 Replies

5. Red Hat

Download speed gradually dropping

RH 4.2.1.13 Hi All, I just installed RH and I am able to connect to the internet via my router. My high speed is such that I should be able to download at over 1000 kb/s. While trying to download oracle database, it is starting at above 1000kb/s and gradually droping to below 40kb/s which... (1 Reply)
Discussion started by: jxh461
1 Replies

6. Solaris

Names dropping out of /etc/aliases

We are having a problem with names being dropped from the /etc/mail/aliases file. There's no pattern to the names being dropped. It is very random. We are running sendmail 8.14.3 on a Solaris 10 server. There are about 9000 lines in the /etc/mail/aliases file. Is there a limitation on... (8 Replies)
Discussion started by: TFord
8 Replies

7. Emergency UNIX and Linux Support

Dropping Connection

Hi folks, We are pushing messages to an IBM MQ queue on a AIX server where our client connects to from their Windows server and pick up the message. The problem is that every now and then the connection drops and the client application cannot pick up the message. Someone has to bring up the... (1 Reply)
Discussion started by: ChicagoBlues
1 Replies

8. Red Hat

Create same file name to directory name without dropping it

Hi, Under '/home' directory, there is one file called 'maddy'.Usually there used to be directories under /home directory. # ls -alrt total 132 drwx------ 2 hcladmin sys 4096 May 30 10:54 admin drwxr-xr-x 29 root root 4096 Aug 27 03:54 .. drwx------ 2 v6admin dba ... (3 Replies)
Discussion started by: Maddy123
3 Replies

9. Solaris

PF refreshes dropping user connections

We often have to update our ipfilter rules on Solaris 11. svcadm refresh ipfilter drops users every time (we're logged in via the global and then a zlogin to the zone in question). Is there any way not to drop user's connections when modifying ipfilter rules and refreshing the service? (2 Replies)
Discussion started by: LittleLebowski
2 Replies

10. UNIX for Beginners Questions & Answers

Pc's dropping connection to NFS

Hi there. I have a problem with pc's dropping their mounts to a network Nas. The Nas is a Synology DiskStation, it has enough concurrent connections which I think off the top of my head is about 200 and I only need 120. So, question 1 is why will a unix box drop a mount, and 2, how can I... (2 Replies)
Discussion started by: MuntyScrunt
2 Replies
WAIT(2) 							System Calls Manual							   WAIT(2)

NAME
wait, waitpid, wait4, wait3 - wait for process terminatation SYNOPSIS
#include <sys/types.h> #include <sys/wait.h> pid = wait(status) int pid; union wait *status; #include <sys/time.h> #include <sys/resource.h> pid = waitpid(wpid, status, options); int pid; int wpid; union wait *status; int options; pid = wait3(status, options, rusage); int pid; union wait *status; int options; struct rusage *rusage; pid = wait4(wpid, status, options, rusage); int pid; int wpid; union wait *status; int options; struct rusage *rusage; DESCRIPTION
The wait function suspends execution of its calling process until status information is available for a terminated child process, or a sig- nal is received. On return from a successful wait call, the status area contains termination information about the process that exited as defined below. The wait4 call provides a more general interface for programs that need to wait for certain child processes, that need resource utilization statistics accummulated by child processes, or that require options. The other wait functions are implemented using wait4 . The wpid parameter specifies the set of child processes for which to wait. If wpid is -1, the call waits for any child process. If wpid is 0, the call waits for any child process in the process group of the caller. If wpid is greater than zero, the call waits for the process with process id wpid . If wpid is less than -1, the call waits for any process whose process group id equals the absolute value of wpid . The status parameter is defined below. The options parameter contains the bitwise OR of any of the following options. The WNOHANG option is used to indicate that the call should not block if there are no processes that wish to report status. If the WUNTRACED option is set, children of the current process that are stopped due to a SIGTTIN , SIGTTOU , SIGTSTP , or SIGSTOP signal also have their status reported. If rusage is non-zero, a summary of the resources used by the terminated process and all its children is returned (this information is cur- rently not available for stopped processes). When the WNOHANG option is specified and no processes wish to report status, wait4 returns a process id of 0. The waitpid call is identical to wait4 with an rusage value of zero. The older wait3 call is the same as wait4 with a wpid value of -1. The following macros may be used to test the manner of exit of the process. One of the first three macros will evaluate to a non-zero (true) value: WIFEXITED(status) - True if the process terminated normally by a call to _exit(2) or exit(2) . WIFSIGNALED(status) - True if the process terminated due to receipt of a signal. WIFSTOPPED(status) - True if the process has not terminated, but has stopped and can be restarted. This macro can be true only if the wait call specified the WUNTRACED option or if the child process is being traced (see ptrace(2)). Depending on the values of those macros, the following macros produce the remaining status information about the child process: WEXITSTATUS(status) - If WIFEXITED(status) is true, evaluates to the low-order 8 bits of the argument passed to _exit(2) or exit(2) by the child. WTERMSIG(status) - If WIFSIGNALED(status) is true, evaluates to the number of the signal that caused the termination of the process. WCOREDUMP(status) If WIFSIGNALED(status) is true, evaluates as true if the termination of the process was accompanied by the creation of a core file containing an image of the process when the signal was received. WSTOPSIG(status) If WIFSTOPPED(status) is true, evaluates to the number of the signal that caused the process to stop. NOTES
See sigvec(2) for a list of termination signals. A status of 0 indicates normal termination. If a parent process terminates without waiting for all of its child processes to terminate, the remaining child processes are assigned the parent process 1 ID (the init process ID). If a signal is caught while any of the wait calls is pending, the call may be interrupted or restarted when the signal-catching routine returns, depending on the options in effect for the signal; see intro(2), System call restart. RETURN VALUES
If wait() returns due to a stopped or terminated child process, the process ID of the child is returned to the calling process. Otherwise, a value of -1 is returned and errno is set to indicate the error. If wait4(), wait3() or waitpid() returns due to a stopped or terminated child process, the process ID of the child is returned to the call- ing process. If there are no children not previously awaited, -1 is returned with errno set to [ECHILD]. Otherwise, if WNOHANG is speci- fied and there are no stopped or exited children, 0 is returned. If an error is detected or a caught signal aborts the call, a value of -1 is returned and errno is set to indicate the error. ERRORS
Wait() will fail and return immediately if: [ECHILD] The calling process has no existing unwaited-for child processes. [EFAULT] The status or rusage arguments point to an illegal address. (May not be detected before exit of a child process.) [EINTR] The call was interrupted by a caught signal, or the signal had the SV_INTERRUPT flag set. STANDARDS
The wait and waitpid functions are defined by POSIX; wait4 and wait3 are not specified by POSIX. The WCOREDUMP macro and the ability to restart a pending wait call are extensions to the POSIX interface. SEE ALSO
exit(2) , sigvec(2) A wait function call appeared in Version 6 AT&T UNIX. 4th Berkeley Distribution March 12, 1993 WAIT(2)
All times are GMT -4. The time now is 03:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy