I used the strace tool to follow it. I touch a file named lastpipe just contain:

    shopt -s lastpipe
    exit 142 | false

run command:

    $ strace /bin/bash lastpipe

the output:

    read(3, "shopt -s lastpipe\nexit 142 | fal"..., 80) = 35
    lseek(3, 0, SEEK_SET)                   = 0
    getrlimit(RLIMIT_NOFILE, {rlim_cur=1024, rlim_max=4*1024}) = 0
fcntl(255, F_GETFD) = -1 EBADF (Bad file descriptor)
    dup2(3, 255)                            = 255
    close(3)                                = 0
    fcntl(255, F_SETFD, FD_CLOEXEC)         = 0
fcntl(255, F_GETFL) = 0x8000 (flags O_RDONLY|O_LARGEFILE)
    fstat(255, {st_mode=S_IFREG|0644, st_size=35, ...}) = 0
    lseek(255, 0, SEEK_CUR)                 = 0
read(255, "shopt -s lastpipe\nexit 142 | fal"..., 35) = 35
    rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
    pipe([3, 4])                            = 0
    rt_sigprocmask(SIG_BLOCK, [INT CHLD], [CHLD], 8) = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fc40e9fb9d0) = 774
    rt_sigprocmask(SIG_SETMASK, [CHLD], NULL, 8) = 0
    close(4)                                = 0
close(4) = -1 EBADF (Bad file descriptor)
    getrlimit(RLIMIT_NOFILE, {rlim_cur=1024, rlim_max=4*1024}) = 0
    fcntl(255, F_GETFD)                     = 0x1 (flags FD_CLOEXEC)
fcntl(254, F_GETFD) = -1 EBADF (Bad file descriptor)
    dup2(0, 254)                            = 254
    close(0)                                = 0
    dup2(3, 0)                              = 0
    close(3)                                = 0
    rt_sigprocmask(SIG_BLOCK, [CHLD], [CHLD], 8) = 0
    rt_sigprocmask(SIG_SETMASK, [CHLD], NULL, 8) = 0
    dup2(254, 0)                            = 0
    close(254)                              = 0
    rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=774, si_uid=0, si_status=142, si_utime=0, si_stime=0} --- wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 142}], WNOHANG, NULL) = 774 wait4(-1, 0x7ffc0efc1658, WNOHANG, NULL) = -1 ECHILD (No child processes)
    rt_sigreturn({mask=[]})                 = 0
    rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGINT, {0x440490, [], SA_RESTORER, 0x7fc40e04b100}, {SIG_DFL, [], SA_RESTORER, 0x7fc40e04b100}, 8) = 0 rt_sigaction(SIGINT, {SIG_DFL, [], SA_RESTORER, 0x7fc40e04b100}, {0x440490, [], SA_RESTORER, 0x7fc40e04b100}, 8) = 0
    rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
    fstat(2, {st_mode=S_IFCHR|0600, st_rdev=makedev(4, 64), ...}) = 0
    ioctl(2, TCGETS, {B115200 opost isig icanon echo ...}) = 0
write(2, "lastpipe: line 3: 774 Exit 142"..., 57lastpipe: line 3: 774 Exit 142 exit 142
    ) = 57
write(2, " 773 Hangup "..., 43 773 Hangup | false
    ) = 43
    read(255, "", 35)                       = 0
    rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
    rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
    exit_group(129)                         = ?
    +++ exited with 129 +++


On 2016年08月10日 19:16, Chet Ramey wrote:
On 8/10/16 3:32 AM, dengke...@windriver.com wrote:
Hi all

When I run the bash test lastpipe.tests, there were some errors occurred.

The code in lastpipe.tests:

     shopt -s lastpipe
     ...
     exit 142 | false
     echo $? -- ${PIPESTATUS[@]}

The error output:

     lastpipe.tests: line 41:   708 Exit 142                exit 142
     703 Hangup                  | false
     129 -- 142 129
I can't reproduce this.  It looks system-specific; there shouldn't be
anything sending a SIGHUP to a simple command there.


Reply via email to