You are not logged in.
Pages: 1
This is my example code, to print a line per second. With any parameters, it will print to stderr, otherwise to stdout.
#include <unistd.h>
#include <stdio.h>
int main(int argc,char* argv[])
{
int i;
FILE* f;
f=argc>1?stderr:stdout;
for(i=0;i<5;++i)
{
fprintf(f,"line %d\n",i);
sleep(1);
}
return 0;
}
When I use " plink.exe [email protected] ./a.out " to execute it, it did not "print a line per second", but print all of the 5 lines after 5 seconds at once.
When use " plink.exe [email protected] ./a.out tostderr " to make it to print to stderr. It works normal.
So I use " plink.exe [email protected] strace ./a.out " to find out what happend.
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({1, 0}, 0xbfeb37f4) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({1, 0}, 0xbfeb37f4) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({1, 0}, 0xbfeb37f4) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({1, 0}, 0xbfeb37f4) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({1, 0}, 0xbfeb37f4) = 0
write(1, "line 0\nline 1\nline 2\nline 3\nline"..., 35) = 35
line 0
line 1
line 2
line 3
line 4
exit_group(0) = ?
There is only one "write(1, "line 0\nline 1\nline 2\nline 3\nline"..., 35) = 35" at last.
Then where am I wrong?
Thanks in advance
Offline
ssh -t 127.0.0.1 ls /proc/self/fd/ -ln
total 0
lrwx------ 1 1000 1000 64 Oct 12 02:42 0 -> /dev/pts/2
lrwx------ 1 1000 1000 64 Oct 12 02:42 1 -> /dev/pts/2
lrwx------ 1 1000 1000 64 Oct 12 02:42 2 -> /dev/pts/2
lr-x------ 1 1000 1000 64 Oct 12 02:42 3 -> /proc/630/fd
ssh 127.0.0.1 ls /proc/self/fd/ -ln
total 0
lr-x------ 1 1000 1000 64 Oct 12 02:44 0 -> pipe:[764]
l-wx------ 1 1000 1000 64 Oct 12 02:44 1 -> pipe:[765]
l-wx------ 1 1000 1000 64 Oct 12 02:44 2 -> pipe:[766]
lr-x------ 1 1000 1000 64 Oct 12 02:44 3 -> /proc/637/fd
plink [email protected] ls /proc/self/fd -ln
total 0
lr-x------ 1 1000 1000 64 Oct 12 02:45 0 -> pipe:[797]
l-wx------ 1 1000 1000 64 Oct 12 02:45 1 -> pipe:[798]
l-wx------ 1 1000 1000 64 Oct 12 02:45 2 -> pipe:[799]
lr-x------ 1 1000 1000 64 Oct 12 02:45 3 -> /proc/661/fd
plink -t [email protected] ls /proc/self/fd -ln
total 0
lrwx------ 1 1000 1000 64 Oct 12 02:49 0 -> /dev/pts/2
lrwx------ 1 1000 1000 64 Oct 12 02:49 1 -> /dev/pts/2
lrwx------ 1 1000 1000 64 Oct 12 02:49 2 -> /dev/pts/2
lr-x------ 1 1000 1000 64 Oct 12 02:49 3 -> /proc/667/fd
Last edited by xinglp (2011-10-11 07:50 PM)
Offline
Pages: 1