wait , , . strace Linux,
% strace -f ./a.out
[lots of stuff]
wait4(-1, strace: Process 29317 attached
<unfinished ...>
[pid 29317] lseek(0, -2, SEEK_CUR) = 0
[pid 29317] exit_group(0) = ?
[pid 29317] +++ exited with 0 +++
<... wait4 resumed> [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 29317
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=29317, si_uid=1000, si_status=0
_utime=0, si_stime=0} ---
[lots of stuff]
fork, . , , fgets , . libc fork. , stdout.
, ... , , <stdio.h> . lseek , 4095 stdin! read write <unistd.h>. , main, - stdin:
if (setvbuf(stdin, NULL, _IONBF, 0) != 0) {
perror("setvbuf:");
exit(1);
}
stdin , . , Linux fgets :
stdio (2) , ; undefined , , , .
, , stdin :
% echo -e '1\n2' | ./a.out
pid: 498, ppid: 21285
buf: 1
pid: 498, ppid: 21285
buf: 2
pid: 498, ppid: 21285
buf: end of getcmd
, , - , .
P.S.
fgets, , .
, .