bash源代码分析----父进程的wait_for函数什么时候返回

(gdb) n
758                 stop_pipeline (asynchronous, (COMMAND *)NULL);
(gdb) n
760                 if (asynchronous)
(gdb) n
775                   exec_result = wait_for (last_made_pid);
(gdb) n

_

父进程执行到这里开始等待子进程返回。


而子进程被我们停在了pipe_read函数的

         while (read (pp[0], &ch, 1) == -1 && errno == EINTR)

这里,下面,我们要调试子进程,直到返回到父进程为止。

(gdb) bt
#0  0x00007ffff76cea30 in __read_nocancel () from /lib64/libc.so.6
#1  0x0000000000440f23 in pipe_read (pp=0x6e0de4 <pgrp_pipe>) at jobs.c:4245
#2  make_child (command=0xab02e8 "ls --color=auto", async_p=async_p@entry=0) at jobs.c:1818
#3  0x00000000004307a5 in execute_disk_command (cmdflags=0, fds_to_close=0xaae3c8, async=0, pipe_out=-1, pipe_in=-1,
    command_line=0xaae2e8 "ls --color=auto", redirects=0x0, words=<optimized out>) at execute_cmd.c:4683
#4  execute_simple_command (simple_command=<optimized out>, pipe_in=pipe_in@entry=-1, pipe_out=pipe_out@entry=-1,
    async=async@entry=0, fds_to_close=fds_to_close@entry=0xaae3c8) at execute_cmd.c:3990
#5  0x0000000000431e9e in execute_command_internal (command=0xa98808, asynchronous=0, pipe_in=-1, pipe_out=-1,
    fds_to_close=0xaae3c8) at execute_cmd.c:735
#6  0x000000000043342e in execute_command (command=0xa98808) at execute_cmd.c:382
#7  0x000000000041e253 in reader_loop () at eval.c:152
#8  0x000000000041c88e in main (argc=1, argv=0x7fffffffe2a8, env=0x7fffffffe2b8) at shell.c:749
(gdb) fini
Run till exit from #0  0x00007ffff76cea30 in __read_nocancel () from /lib64/libc.so.6
0x0000000000440f23 in pipe_read (pp=0x6e0de4 <pgrp_pipe>) at jobs.c:4245
4245          while (read (pp[0], &ch, 1) == -1 && errno == EINTR)
(gdb)

 

#if defined (PGRP_PIPE)
      if (pipeline_pgrp == mypid)
        pipe_read (pgrp_pipe);
#endif
    }
      else            /* Without job control... */
    {
      if (pipeline_pgrp == 0)
        pipeline_pgrp = shell_pgrp;

      /* If these signals are set to SIG_DFL, we encounter the curious
         situation of an interactive ^Z to a running process *working*
         and stopping the process, but being unable to do anything with
         that process to change its state.  On the other hand, if they
         are set to SIG_IGN, jobs started from scripts do not stop when
         the shell running the script gets a SIGTSTP and stops. */

      default_tty_job_signals ();
    }

#if defined (PGRP_PIPE)
      /* Release the process group pipe, since our call to setpgid ()
     is done.  The last call to sh_closepipe is done in stop_pipeline. */
      sh_closepipe (pgrp_pipe);
#endif /* PGRP_PIPE */

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值