1
[root@localhost /]# ( ./address_to_char;cat) | ./overflow

How does ( ./address_to_char;cat) work here?

What's different from ./address_to_char|./overflow?

2 Answers 2

1

The outputs of both ./address_to_char and cat are piped to ./overflow as a single, continuous stream of data.

  1. First, ./address_to_char is run, and its output is redirected to ./overflow's input.

  2. When ./address_to_char exits, cat is started, and its output is attached to the still-running ./overflow process in the same way.

    Since cat was run with no files specified, it reads from stdin (in this case, your keyboard).

6
  • @grawity,when will cat in subshell exit?
    – kernel
    Apr 17, 2011 at 15:12
  • @kernel: cat exits upon reaching the end of its input. In this case, it reads from keyboard, and will exit when you press the "EOF" key (by default Ctrl-D).
    – user1686
    Apr 17, 2011 at 15:17
  • @grawity,but after testing it seems it will also exit when ./overflow exits,weird...or is that normal?
    – kernel
    Apr 17, 2011 at 15:18
  • @kernel: It's normal. When the right side (./overflow) exits, the left side doesn't have anywhere to write to, and -- AFAIK -- gets killed by signal SIGPIPE.
    – user1686
    Apr 17, 2011 at 15:23
  • @grawity,that solves most of my doubt,but still one, how can ./overflow get executed before cat exits?
    – kernel
    Apr 17, 2011 at 15:28
1

Well the parentheses open a sub shell and the semi colon will run the commands sequentially.

So in this case, you are running ./address_to_char then cat in a subshell.

4
  • How does the subshell interact with ./overflow?
    – kernel
    Apr 17, 2011 at 8:53
  • stderr and stdout are returned and piped into overflow
    – kband
    Apr 17, 2011 at 9:08
  • The output of the subshell is then redirected into ./overflow
    – Troydm
    Apr 17, 2011 at 9:08
  • It seems there's no difference from ./address_to_char | ./overflow,right?
    – kernel
    Apr 17, 2011 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.