AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.

 View Only
  • 1.  Who added signal handlers to /bin/sleep in AIX 6.1 ?

    Posted Mon May 16, 2011 12:13 PM

    Originally posted by: dickdunbar


    This is really silly; why would IBM change base functionality like this?

    sleep 100000 &
    1234

    kill 1234

    SIGTERM is ignored.

    kill -6 1234
    dbx /bin/sleep core
    (dbx) proc signal
    (3) QUIT: SIG_IGN
    (15) TERM: SIG_IGN

    Which means a script like this cannot be killed with the default TERM signal.

    #!/bin/ksh
    trap "echo $(/bin/date +%Y%m%d-%H%M%S) ' (sigTERM)' ; exit 0 " 15
    while true ; do
    sleep 10
    # probe somebody near you
    done

    The most likely command to be running in this script is "sleep"
    Since it ignores the signal, so does the shell script.

    $ oslevel -s
    6100-02-05-0939
    $ lslpp -w /usr/bin/sleep
    File Fileset Type
    /usr/bin/sleep bos.rte.control File
    $ lslpp -l bos.rte.control
    Fileset Level State Description
    bos.rte.control 6.1.2.4 COMMITTED System Control Commands

    Has this been fixed yet?


  • 2.  Re: Who added signal handlers to /bin/sleep in AIX 6.1 ?

    Posted Mon May 16, 2011 02:37 PM

    Originally posted by: shargus


    Works ok on my system (aix53 tl12 sp2)...
    Seems kinda silly for sleep to be trapping signals... are you sure you're running the correct "sleep"?
    A recently-patched AIX6.1 server (6.1 TL6 SP3) /usr/bin/sleep is 2968 bytes long, and dated Oct 05, 2007.

    
    $ ls -l /usr/bin/sleep -r-xr-xr-x    1 bin      bin            2968 Oct 05 2007  /usr/bin/sleep
    


    The /bin directory is a soft-link to the /usr/bin directory.

    Could it be your shell is trapping the signals? Type "trap" at a shell prompt and see if any signals are set to ignore.


  • 3.  Re: Who added signal handlers to /bin/sleep in AIX 6.1 ?

    Posted Mon May 16, 2011 06:11 PM

    Originally posted by: dickdunbar


    Yes, of course it works on AIX 5.3.

    I gave some AIX 5.3 scripts to a customer; they couldn't stop the script,
    and there is nothing I can do about it ... well, perhaps

    • give them the sleep binary from AIX 5.3
    • tell them to use a signal that isn't handled ( kill -INT 1234 )

    Some customers don't even allow the "kill" command on their production machines.

    The test is a bit simpler than I wrote:

    /bin/sleep 100000 &
    1235

    dbx -a 1234
    proc signal

    I'm can't imagine any scenario where "the BIG sleep" is useful.


  • 4.  Re: Who added signal handlers to /bin/sleep in AIX 6.1 ?

    Posted Mon May 16, 2011 09:30 PM

    Originally posted by: dickdunbar


    Well, shipping AIX 5.3 version of sleep doesn't solve anything.

    This is just a cover module, that links to the implementation of
    sleep() in libc.a, which then calls nsleep in libc.a

    Running 5.3 version of sleep results in exactly the same behaviour,
    which of course can be expected.

    The problem runs deeper ... and longer ... perhaps I can call "nap"
    so I can cut my sleep time when the gun goes off.

    Observing sleep with truss, no signal handling functions are called.

    $ truss ./sleep 10
    execve("./sleep", 0x2FF22A44, 0x20012818) argc: 2
    _nsleep(0x2FF228E0, 0x2FF22958) (sleeping...)
    _nsleep(0x2FF228E0, 0x2FF22958) = 0
    kfcntl(1, F_GETFL, 0x2FF22FFC) = 67108866
    kfcntl(2, F_GETFL, 0x00000000) = 67108866
    _exit(0)

    Using example 2 from "man sleep" in a shell script, looks something like this:
    
    #!/bin/ksh # truss -af tsleep.sh #define SIGQUIT    3    
    /* (*) quit, generated from terminal special char */ #define SIGTERM   15    
    /* software termination signal */ #define SIGCHLD   20    
    /* (+) sent to parent on child stop or exit */ #define SIGXFSZ   25    
    /* file size limit exceeded (see setrlimit()) */ export LANG=C trap 
    "echo $(/bin/date '+%Y%m%d-%H%M%S  sigTERM') ; exit 0 " 15 
    
    while 
    
    true 
    
    do #   date                  ## Skip the date call 
    
    for truss. /usr/bin/sleep 5 done
    

    ----
    AIX 5.3 invocation: truss -af tsleep.sh
    
    $  truss -af tsleep.sh 802866: execve(
    "/usr/bin/tsleep.sh", 0x2FF228C8, 0x2000FAE8)  argc: 3 . . . 802866: _sigaction(6, 0x00000000, 0x2FF22540)           = 0 802866: _sigaction(6, 0x2FF22540, 0x2FF22550)           = 0 802866: _sigaction(14, 0x00000000, 0x2FF22540)          = 0 802866: _sigaction(14, 0x2FF22540, 0x2FF22550)          = 0 802866: _sigaction(10, 0x00000000, 0x2FF22540)          = 0 802866: _sigaction(10, 0x2FF22540, 0x2FF22550)          = 0 802866: _sigaction(20, 0x00000000, 0x2FF22540)          = 0 802866: _sigaction(20, 0x2FF22540, 0x2FF22550)          = 0 802866: _sigaction(7, 0x00000000, 0x2FF22540)           = 0 802866: _sigaction(7, 0x2FF22540, 0x2FF22550)           = 0 802866: _sigaction(8, 0x00000000, 0x2FF22540)           = 0 802866: _sigaction(8, 0x2FF22540, 0x2FF22550)           = 0 802866: _sigaction(1, 0x00000000, 0x2FF22540)           = 0 802866: _sigaction(1, 0x2FF22540, 0x2FF22550)           = 0 802866: _sigaction(4, 0x00000000, 0x2FF22540)           = 0 802866: _sigaction(4, 0x2FF22540, 0x2FF22550)           = 0 802866: _sigaction(2, 0x00000000, 0x2FF224F0)           = 0 802866: _sigaction(2, 0x2FF224F0, 0x2FF22500)           = 0 802866: _sigaction(13, 0x00000000, 0x2FF22540)          = 0 802866: _sigaction(13, 0x2FF22540, 0x2FF22550)          = 0 802866: _sigaction(3, 0x00000000, 0x2FF22500)           = 0 802866: _sigaction(3, 0x2FF22500, 0x2FF22510)           = 0 802866: _sigaction(12, 0x00000000, 0x2FF22540)          = 0 802866: _sigaction(12, 0x2FF22540, 0x2FF22550)          = 0 802866: _sigaction(15, 0x00000000, 0x2FF22540)          = 0 802866: _sigaction(15, 0x2FF22540, 0x2FF22550)          = 0 802866: _sigaction(5, 0x00000000, 0x2FF22540)           = 0 802866: _sigaction(5, 0x2FF22540, 0x2FF22550)           = 0 802866: _sigaction(30, 0x00000000, 0x2FF22540)          = 0 802866: _sigaction(30, 0x2FF22540, 0x2FF22550)          = 0 802866: _sigaction(31, 0x00000000, 0x2FF22540)          = 0 802866: _sigaction(31, 0x2FF22540, 0x2FF22550)          = 0 802866: _sigaction(25, 0x00000000, 0x2FF22500)          = 0 802866: _sigaction(25, 0x2FF22500, 0x2FF22510)          = 0 . . 802866: _sigaction(20, 0x00000000, 0x2FF22010)          = 0 802866: _sigaction(20, 0x2FF22010, 0x2FF22020)          = 0 802866: kioctl(2, 22528, 0x00000000, 0x00000000)        = 0 802866: kioctl(2, 21505, 0x2000C180, 0x00000000)        = 0 802866: kfork()                                         = 757900 757900: kfork()         (returning as child ...)        = 0 802866: _sigaction(20, 0x00000000, 0x2FF22010)          = 0 757900: _getpid()                                       = 757900 802866: _sigaction(20, 0x2FF22010, 0x2FF22020)          = 0 757900: _sigaction(25, 0x00000000, 0x2FF22030)          = 0 757900: _sigaction(25, 0x2FF22030, 0x2FF22040)          = 0 757900: _sigaction(15, 0x00000000, 0x2FF22030)          = 0 757900: _sigaction(15, 0x2FF22030, 0x2FF22040)          = 0 757900: _sigaction(3, 0x00000000, 0x2FF22030)           = 0 757900: _sigaction(3, 0x2FF22030, 0x2FF22040)           = 0 757900: execve(
    "/usr/bin/sleep", 0x20095BF8, 0x20095CC8)  argc: 2 757900:  argv: /usr/bin/sleep 5 802866: kwaitpid(0x2FF22080, -1, 6, 0x00000000, 0x00000000) (sleeping...) 757900: _nsleep(0x2FF22760, 0x2FF227D8) (sleeping...) 757900: _nsleep(0x2FF22760, 0x2FF227D8)                 = 0 757900: kfcntl(1, F_GETFL, 0x2FF22FFC)                  = 2 757900: kfcntl(2, F_GETFL, 0x00000000)                  = 2 757900: _exit(0)
    


  • 5.  Re: Who added signal handlers to /bin/sleep in AIX 6.1 ?

    Posted Mon May 16, 2011 08:41 PM

    Originally posted by: shargus


    I tried it on a 6.1 server - worked there too.


  • 6.  Re: Who added signal handlers to /bin/sleep in AIX 6.1 ?

    Posted Tue May 17, 2011 01:15 AM

    Originally posted by: dickdunbar


    > shargus : I tried it on a 6.1 server - worked there too.

    Can you provide some details for your 6.1 environment, please:

    oslevel -s
    6100-02-05-0939
    lslpp -L bos.rte.libc
    6.1.2.6


  • 7.  Re: Who added signal handlers to /bin/sleep in AIX 6.1 ?

    Posted Tue May 17, 2011 01:48 AM

    Originally posted by: dickdunbar


    oslevel 6100-06-04-112


    This level fixes the problem. I should have looked for an updated machine.
    Thanks shargus for the feedback.


  • 8.  Re: Who added signal handlers to /bin/sleep in AIX 6.1 ?

    Posted Mon May 16, 2011 09:38 PM

    Originally posted by: dickdunbar


    AIX 6.1 invocation: truss -af tsleep.sh
    Looks exactly like 5.3, so the question is: who is setting the signal handlers for sleep?

    
    truss -af tsleep.sh . . . 688340: _sigaction(20, 0x00000000, 0x2FF22100)          = 0 688340: _sigaction(20, 0x2FF22100, 0x2FF22110)          = 0 688340: kfork() = 430128 430128: kfork()         (returning as child ...)        = 0 688340: _sigaction(20, 0x00000000, 0x2FF22100)430128:   _getpid() 688340: _sigaction(20, 0x2FF22100, 0x2FF22110)          = 0 430128: _sigaction(25, 0x00000000, 0x2FF22110)          = 0 430128: _sigaction(25, 0x2FF22110, 0x2FF22120)          = 0 430128: execve(
    "/usr/bin/sleep", 0x20096588, 0x20096658)  argc: 2 430128:  argv: /usr/bin/sleep 5 688340: kwaitpid(0x2FF22170, -1, 6, 0x00000000, 0x00000000) (sleeping...) 430128: _nsleep(0x2FF22880, 0x2FF228F8) (sleeping...) 430128: _nsleep(0x2FF22880, 0x2FF228F8)                 = 0 430128: kfcntl(1, F_GETFL, 0x2FF22FFC)                  = 2 430128: kfcntl(2, F_GETFL, 0x00000000)                  = 2 430128: _exit(0) 688340: kwaitpid(0x2FF22170, -1, 6, 0x00000000, 0x00000000) = 430128 688340: _sigaction(20, 0x00000000, 0x2FF22100)          = 0 688340: _sigaction(20, 0x2FF22100, 0x2FF22110)          = 0 688340: kfork()                                         = 798804 798804: kfork()         (returning as child ...)        = 0 688340: _sigaction(20, 0x00000000, 0x2FF22100)798804:   _getpid() 688340: _sigaction(20, 0x2FF22100, 0x2FF22110)          = 0 798804: _sigaction(25, 0x00000000, 0x2FF22110)          = 0 798804: _sigaction(25, 0x2FF22110, 0x2FF22120)          = 0 798804: execve(
    "/usr/bin/sleep", 0x20096588, 0x20096658)  argc: 2 798804:  argv: /usr/bin/sleep 5 688340: kwaitpid(0x2FF22170, -1, 6, 0x00000000, 0x00000000) (sleeping...) 798804: _nsleep(0x2FF22880, 0x2FF228F8) (sleeping...) 798804: _nsleep(0x2FF22880, 0x2FF228F8)                 = 0 798804: kfcntl(1, F_GETFL, 0x2FF22FFC)                  = 2 798804: kfcntl(2, F_GETFL, 0x00000000)                  = 2 798804: _exit(0) 688340: kwaitpid(0x2FF22170, -1, 6, 0x00000000, 0x00000000) = 798804 688340: _sigaction(20, 0x00000000, 0x2FF22100)          = 0 688340: _sigaction(20, 0x2FF22100, 0x2FF22110)          = 0
    


  • 9.  Re: Who added signal handlers to /bin/sleep in AIX 6.1 ?

    Posted Mon May 16, 2011 10:01 PM

    Originally posted by: dickdunbar


    One more test, just to make sure the shell "trap" functionality works.
    ksh and bash respond the same way on both version of AIX.

    
    #!/bin/bash # truss -af tsleep.sh #define SIGINT     2    
    /* interrupt, generated from terminal special char */ #define SIGQUIT    3    
    /* (*) quit, generated from terminal special char */ #define SIGTERM   15    
    /* software termination signal */ #define SIGCHLD   20    
    /* (+) sent to parent on child stop or exit */ #define SIGXFSZ   25    
    /* file size limit exceeded (see setrlimit()) */ export LANG=C trap 
    "echo $(/bin/date '+%Y%m%d-%H%M%S  sigINT ') ; exit 0 "  2 trap 
    "echo $(/bin/date '+%Y%m%d-%H%M%S  sigTERM') ; exit 0 " 15 
    
    while 
    
    true 
    
    do /usr/bin/sleep 5 done
    


    Sample invocation:
    
    # works on AIX 5.3, ignored on AIX 6.1 $ tsleep.sh & [1] 757932 bash-3.2$ kill %1 Terminated 20110516-195714 sigTERM   # works on AIX 5.3 and AIX 6.1   $ kill -INT %1 20110516-195021 sigINT
    


  • 10.  Re: Who added signal handlers to /bin/sleep in AIX 6.1 ?

    Posted Tue May 17, 2011 01:05 AM

    Originally posted by: dickdunbar


    Another work-around attempt.


    sleep is a built-in ksh command, processed internally by the shell.

    /bin/ksh implements built-in sleep using exece(sleep), so it inherits the same signal handling attributes as /bin/sleep.

    /bin/ksh93 implements "sleep 5" using _poll(addr, 0, 5000), so bypasses _nsleep signal handling in libc.a

    Is sigTERM still ignored with this sleep implementation?
    Sadly, yes: AIX 6.1 still ignores kill %1

    tsleep.sh
    
    #!/bin/ksh93 trap 
    "echo $(/bin/date '+%Y%m%d-%H%M%S  sigINT ') ; exit 0 "  2 trap 
    "echo $(/bin/date '+%Y%m%d-%H%M%S  sigTERM') ; exit 0 " 15 
    
    while 
    
    true ; 
    
    do sleep 5 done
    


    AIX 6.1 tsleep.sh &
    
    (dbx) proc signal (2)     INT:    0x200133f0              (sh_fault) (3)    QUIT:    0x200133f0              (sh_fault) (14)    ALRM:   0x20013428              (sigalrm) (15)    TERM:   SIG_IGN (20)    CHLD:   0x200139c4              (job_waitsafe)
    


    AIX 5.3 tsleep.sh &
    
    (dbx) proc signal (2)     INT:    0x2001379c              (sh_fault) (3)    QUIT:    0x2001379c              (sh_fault) (14)    ALRM:   0x200137f0              (sigalrm) (15)    TERM:   0x2001379c              (sh_fault) (20)    CHLD:   0x20013d50              (job_waitsafe)