How come _exit(0) (exiting by syscall) prevents me from receiving any stdout content?

前端 未结 3 1032
你的背包
你的背包 2021-01-19 03:12

I have a Linux x86-32 GAS assembly program terminating like this:

movl $1, %eax
movl $0, %ebx # argument for _exit
int $0x80

When I exit li

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-19 03:42

    According to the man page for _exit(2)

    Whether it flushes standard I/O buffers and removes temporary files created with tmpfile(3) is implementation-dependent. On the other hand, _exit() does close open file descriptors, and this may cause an unknown delay, waiting for pending output to finish. If the delay is undesired, it may be useful to call functions like tcflush(3) before calling _exit(). Whether any pending I/O is canceled, and which pending I/O may be canceled upon _exit(), is implementation-dependent.

    So unless you've flushed stdout, it may get discarded.

提交回复
热议问题