Chinaunix首页 | 论坛 | 博客
  • 博客访问: 972805
  • 博文数量: 99
  • 博客积分: 3306
  • 博客等级: 中校
  • 技术积分: 1238
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-21 10:14
文章分类

全部博文(99)

文章存档

2012年(37)

2011年(56)

2010年(6)

分类: Python/Ruby

2012-03-03 17:30:56

 前两天想用perl写个daemon进程来做些事情,但是后来发现日志一直没有办法打出来。先看类似的脚本
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. open LOG,">test.out" or die "open file failed\n";
  5. foreach my $k (0..25)
  6. {

  7.         print LOG ($k,"\n");
  8.         sleep(1);
  9. }
在运行这个脚本后,我们可以另外开个窗口,然后你会发现tail -f test.out的时候一直没有任何输出,直到最后程序结束的时候才会一下子都显示出来的。

strace一下我们可以发现
  1. $ strace ./c.pl |tee ss.log
  2. execve("./c.pl", ["./c.pl"], [/* 27 vars */]) = 0
  3. brk(0) = 0x63b0000
  4. mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b6176354000
  5. uname({sys="Linux", node="free71-170-stable.alipay.net", ...}) = 0
  6. access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
  7. open("/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/tls/x86_64/libperl.so", O_RDONLY) = -1 ENOENT (No such file or directory)
  8. stat("/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/tls/x86_64", 0x7fff41a3c490) = -1 ENOENT (No such file or directory)
  9. open("/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/tls/libperl.so", O_RDONLY) = -1 ENOENT (No such file or directory)
  10. stat("/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/tls", 0x7fff41a3c490) = -1 ENOENT (No such file or directory)
  11. open("/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/x86_64/libperl.so", O_RDONLY) = -1 ENOENT (No such file or directory)
  12. stat("/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/x86_64", 0x7fff41a3c490) = -1 ENOENT (No such file or directory)
  13. open("/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libperl.so", O_RDONLY) = 3
  14. read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\340\34\3\3004\0\0\0"..., 832) = 832
  15. fstat(3, {st_mode=S_IFREG|0755, st_size=1262288, ...}) = 0
  16. mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b6176355000
  17. mmap(0x34c0000000, 3363552, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x34c0000000
  18. mprotect(0x34c012b000, 2097152, PROT_NONE) = 0
  19. mmap(0x34c032b000, 36864, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x12b000) = 0x34c032b000
  20. mmap(0x34c0334000, 4832, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x34c0334000
  21. close(3) = 0
  22. open("/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libresolv.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
  23. open("/etc/ld.so.cache", O_RDONLY) = 3
  24. fstat(3, {st_mode=S_IFREG|0644, st_size=81032, ...}) = 0
  25. mmap(NULL, 81032, PROT_READ, MAP_PRIVATE, 3, 0) = 0x2b6176356000
  26. close(3) = 0
  27. open("/lib64/libresolv.so.2", O_RDONLY) = 3
  28. read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\2402@\3054\0\0\0"..., 832) = 832
  29. fstat(3, {st_mode=S_IFREG|0755, st_size=92736, ...}) = 0
  30. mmap(0x34c5400000, 2181864, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x34c5400000
  31. mprotect(0x34c5411000, 2097152, PROT_NONE) = 0
  32. mmap(0x34c5611000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x11000) = 0x34c5611000
  33. mmap(0x34c5613000, 6888, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x34c5613000
  34. close(3) = 0
  35. open("/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libnsl.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
  36. open("/lib64/libnsl.so.1", O_RDONLY) = 3
  37. read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\240@\0\3024\0\0\0"..., 832) = 832
  38. fstat(3, {st_mode=S_IFREG|0755, st_size=114352, ...}) = 0
  39. mmap(0x34c2000000, 2194096, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x34c2000000
  40. mprotect(0x34c2015000, 2093056, PROT_NONE) = 0
  41. mmap(0x34c2214000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x14000) = 0x34c2214000
  42. mmap(0x34c2216000, 6832, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x34c2216000
  43. close(3) = 0
  44. open("/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libdl.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
  45. open("/lib64/libdl.so.2", O_RDONLY) = 3
  46. read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\20\16\0\2764\0\0\0"..., 832) = 832
  47. fstat(3, {st_mode=S_IFREG|0755, st_size=23360, ...}) = 0
  48. mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b617636a000
  49. mmap(0x34be000000, 2109696, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x34be000000
  50. mprotect(0x34be002000, 2097152, PROT_NONE) = 0
  51. mmap(0x34be202000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x34be202000
  52. close(3) = 0
  53. open("/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libm.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
  54. open("/lib64/libm.so.6", O_RDONLY) = 3
  55. read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`>@\2764\0\0\0"..., 832) = 832
  56. fstat(3, {st_mode=S_IFREG|0755, st_size=615136, ...}) = 0
  57. mmap(0x34be400000, 2629848, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x34be400000
  58. mprotect(0x34be482000, 2093056, PROT_NONE) = 0
  59. mmap(0x34be681000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x81000) = 0x34be681000
  60. close(3) = 0
  61. open("/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libcrypt.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
  62. open("/lib64/libcrypt.so.1", O_RDONLY) = 3
  63. read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\360\t\300\2774\0\0\0"..., 832) = 832
  64. fstat(3, {st_mode=S_IFREG|0755, st_size=48600, ...}) = 0
  65. mmap(0x34bfc00000, 2322880, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x34bfc00000
  66. mprotect(0x34bfc09000, 2093056, PROT_NONE) = 0
  67. mmap(0x34bfe08000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x8000) = 0x34bfe08000
  68. mmap(0x34bfe0a000, 184768, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x34bfe0a000
  69. close(3) = 0
  70. open("/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libutil.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
  71. open("/lib64/libutil.so.1", O_RDONLY) = 3
  72. read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\200\16\340\3154\0\0\0"..., 832) = 832
  73. fstat(3, {st_mode=S_IFREG|0755, st_size=18152, ...}) = 0
  74. mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b617636b000
  75. mmap(0x34cde00000, 2105616, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x34cde00000
  76. mprotect(0x34cde02000, 2093056, PROT_NONE) = 0
  77. mmap(0x34ce001000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1000) = 0x34ce001000
  78. close(3) = 0
  79. open("/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
  80. open("/lib64/libpthread.so.0", O_RDONLY) = 3
  81. read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\240W\200\2764\0\0\0"..., 832) = 832
  82. fstat(3, {st_mode=S_IFREG|0755, st_size=145824, ...}) = 0
  83. mmap(0x34be800000, 2204528, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x34be800000
  84. mprotect(0x34be816000, 2093056, PROT_NONE) = 0
  85. mmap(0x34bea15000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x15000) = 0x34bea15000
  86. mmap(0x34bea17000, 13168, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x34bea17000
  87. close(3) = 0
  88. open("/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
  89. open("/lib64/libc.so.6", O_RDONLY) = 3
  90. read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\220\332\301\2754\0\0\0"..., 832) = 832
  91. fstat(3, {st_mode=S_IFREG|0755, st_size=1717800, ...}) = 0
  92. mmap(0x34bdc00000, 3498328, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x34bdc00000
  93. mprotect(0x34bdd4e000, 2093056, PROT_NONE) = 0
  94. mmap(0x34bdf4d000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x14d000) = 0x34bdf4d000
  95. mmap(0x34bdf52000, 16728, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x34bdf52000
  96. close(3) = 0
  97. mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b617636c000
  98. mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b617636d000
  99. arch_prctl(ARCH_SET_FS, 0x2b617636d250) = 0
  100. mprotect(0x34c5611000, 4096, PROT_READ) = 0
  101. mprotect(0x34c2214000, 4096, PROT_READ) = 0
  102. mprotect(0x34be202000, 4096, PROT_READ) = 0
  103. mprotect(0x34be681000, 4096, PROT_READ) = 0
  104. mprotect(0x34bfe08000, 4096, PROT_READ) = 0
  105. mprotect(0x34ce001000, 4096, PROT_READ) = 0
  106. mprotect(0x34bea15000, 4096, PROT_READ) = 0
  107. mprotect(0x34bdf4d000, 16384, PROT_READ) = 0
  108. mprotect(0x34bda1b000, 4096, PROT_READ) = 0
  109. munmap(0x2b6176356000, 81032) = 0
  110. set_tid_address(0x2b617636d2e0) = 3872
  111. set_robust_list(0x2b617636d2f0, 0x18) = 0
  112. futex(0x7fff41a3cfbc, FUTEX_WAKE_PRIVATE, 1) = 0
  113. rt_sigaction(SIGRTMIN, {0x34be805380, [], SA_RESTORER|SA_SIGINFO, 0x34be80eb10}, NULL, 8) = 0
  114. rt_sigaction(SIGRT_1, {0x34be8052b0, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x34be80eb10}, NULL, 8) = 0
  115. rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
  116. getrlimit(RLIMIT_STACK, {rlim_cur=10240*1024, rlim_max=RLIM_INFINITY}) = 0
  117. rt_sigaction(SIGFPE, {0x1, [FPE], SA_RESTORER|SA_RESTART, 0x34bdc302d0}, {SIG_DFL, [], 0}, 8) = 0
  118. brk(0) = 0x63b0000
  119. brk(0x63d2000) = 0x63d2000
  120. getuid() = 1801
  121. geteuid() = 1801
  122. getgid() = 1000
  123. getegid() = 1000
  124. open("/usr/lib/locale/locale-archive", O_RDONLY) = 3
  125. fstat(3, {st_mode=S_IFREG|0644, st_size=56466992, ...}) = 0
  126. mmap(NULL, 56466992, PROT_READ, MAP_PRIVATE, 3, 0) = 0x2b617636e000
  127. close(3) = 0
  128. mmap(NULL, 135168, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b6179948000
  129. open("/dev/urandom", O_RDONLY) = 3
  130. read(3, "Q\3\7w", 4) = 4
  131. close(3) = 0
  132. time([1330767532]) = 1330767532
  133. stat("/usr/lib64/perl5/site_perl/5.8.7/x86_64-linux-thread-multi", 0x7fff41a3cc70) = -1 ENOENT (No such file or directory)
  134. stat("/usr/lib/perl5/site_perl/5.8.7", 0x7fff41a3cc70) = -1 ENOENT (No such file or directory)
  135. stat("/usr/lib64/perl5/site_perl/5.8.6/x86_64-linux-thread-multi", 0x7fff41a3cc70) = -1 ENOENT (No such file or directory)
  136. stat("/usr/lib/perl5/site_perl/5.8.6", 0x7fff41a3cc70) = -1 ENOENT (No such file or directory)
  137. stat("/usr/lib64/perl5/site_perl/5.8.5/x86_64-linux-thread-multi", 0x7fff41a3cc70) = -1 ENOENT (No such file or directory)
  138. stat("/usr/lib/perl5/site_perl/5.8.5", 0x7fff41a3cc70) = -1 ENOENT (No such file or directory)
  139. stat("/usr/lib64/perl5/vendor_perl/5.8.7/x86_64-linux-thread-multi", 0x7fff41a3cc70) = -1 ENOENT (No such file or directory)
  140. stat("/usr/lib/perl5/vendor_perl/5.8.7", 0x7fff41a3cc70) = -1 ENOENT (No such file or directory)
  141. stat("/usr/lib64/perl5/vendor_perl/5.8.6/x86_64-linux-thread-multi", 0x7fff41a3cc70) = -1 ENOENT (No such file or directory)
  142. stat("/usr/lib/perl5/vendor_perl/5.8.6", 0x7fff41a3cc70) = -1 ENOENT (No such file or directory)
  143. stat("/usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi", 0x7fff41a3cc70) = -1 ENOENT (No such file or directory)
  144. stat("/usr/lib/perl5/vendor_perl/5.8.5", 0x7fff41a3cc70) = -1 ENOENT (No such file or directory)
  145. ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
  146. lseek(0, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek)
  147. ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff41a3ca30) = -1 EINVAL (Invalid argument)
  148. lseek(1, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek)
  149. ioctl(2, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
  150. lseek(2, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek)
  151. open("./c.pl", O_RDONLY) = 3
  152. ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff41a3cb40) = -1 ENOTTY (Inappropriate ioctl for device)
  153. lseek(3, 0, SEEK_CUR) = 0
  154. fcntl(3, F_SETFD, FD_CLOEXEC) = 0
  155. fstat(3, {st_mode=S_IFREG|0755, st_size=191, ...}) = 0
  156. rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
  157. readlink("/proc/self/exe", "/usr/bin/perl"..., 4095) = 13
  158. brk(0x63f3000) = 0x63f3000
  159. read(3, "#!/usr/bin/perl\nuse strict;\nuse "..., 4096) = 191
  160. stat("/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/strict.pmc", 0x7fff41a3c770) = -1 ENOENT (No such file or directory)
  161. stat("/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/strict.pm", 0x7fff41a3c630) = -1 ENOENT (No such file or directory)
  162. stat("/usr/lib/perl5/site_perl/5.8.8/strict.pmc", 0x7fff41a3c770) = -1 ENOENT (No such file or directory)
  163. stat("/usr/lib/perl5/site_perl/5.8.8/strict.pm", 0x7fff41a3c630) = -1 ENOENT (No such file or directory)
  164. stat("/usr/lib/perl5/site_perl/strict.pmc", 0x7fff41a3c770) = -1 ENOENT (No such file or directory)
  165. stat("/usr/lib/perl5/site_perl/strict.pm", 0x7fff41a3c630) = -1 ENOENT (No such file or directory)
  166. stat("/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/strict.pmc", 0x7fff41a3c770) = -1 ENOENT (No such file or directory)
  167. stat("/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/strict.pm", 0x7fff41a3c630) = -1 ENOENT (No such file or directory)
  168. stat("/usr/lib/perl5/vendor_perl/5.8.8/strict.pmc", 0x7fff41a3c770) = -1 ENOENT (No such file or directory)
  169. stat("/usr/lib/perl5/vendor_perl/5.8.8/strict.pm", 0x7fff41a3c630) = -1 ENOENT (No such file or directory)
  170. stat("/usr/lib/perl5/vendor_perl/strict.pmc", 0x7fff41a3c770) = -1 ENOENT (No such file or directory)
  171. stat("/usr/lib/perl5/vendor_perl/strict.pm", 0x7fff41a3c630) = -1 ENOENT (No such file or directory)
  172. stat("/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/strict.pmc", 0x7fff41a3c770) = -1 ENOENT (No such file or directory)
  173. stat("/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/strict.pm", 0x7fff41a3c630) = -1 ENOENT (No such file or directory)
  174. stat("/usr/lib/perl5/5.8.8/strict.pmc", 0x7fff41a3c770) = -1 ENOENT (No such file or directory)
  175. stat("/usr/lib/perl5/5.8.8/strict.pm", {st_mode=S_IFREG|0644, st_size=3292, ...}) = 0
  176. open("/usr/lib/perl5/5.8.8/strict.pm", O_RDONLY) = 4
  177. ioctl(4, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff41a3c3c0) = -1 ENOTTY (Inappropriate ioctl for device)
  178. lseek(4, 0, SEEK_CUR) = 0
  179. read(4, "package strict;\n\n$strict::VERSIO"..., 4096) = 3292
  180. lseek(4, 598, SEEK_SET) = 598
  181. lseek(4, 0, SEEK_CUR) = 598
  182. close(4) = 0
  183. stat("/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/warnings.pmc", 0x7fff41a3c770) = -1 ENOENT (No such file or directory)
  184. stat("/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/warnings.pm", 0x7fff41a3c630) = -1 ENOENT (No such file or directory)
  185. stat("/usr/lib/perl5/site_perl/5.8.8/warnings.pmc", 0x7fff41a3c770) = -1 ENOENT (No such file or directory)
  186. stat("/usr/lib/perl5/site_perl/5.8.8/warnings.pm", 0x7fff41a3c630) = -1 ENOENT (No such file or directory)
  187. stat("/usr/lib/perl5/site_perl/warnings.pmc", 0x7fff41a3c770) = -1 ENOENT (No such file or directory)
  188. stat("/usr/lib/perl5/site_perl/warnings.pm", 0x7fff41a3c630) = -1 ENOENT (No such file or directory)
  189. stat("/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/warnings.pmc", 0x7fff41a3c770) = -1 ENOENT (No such file or directory)
  190. stat("/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/warnings.pm", 0x7fff41a3c630) = -1 ENOENT (No such file or directory)
  191. stat("/usr/lib/perl5/vendor_perl/5.8.8/warnings.pmc", 0x7fff41a3c770) = -1 ENOENT (No such file or directory)
  192. stat("/usr/lib/perl5/vendor_perl/5.8.8/warnings.pm", 0x7fff41a3c630) = -1 ENOENT (No such file or directory)
  193. stat("/usr/lib/perl5/vendor_perl/warnings.pmc", 0x7fff41a3c770) = -1 ENOENT (No such file or directory)
  194. stat("/usr/lib/perl5/vendor_perl/warnings.pm", 0x7fff41a3c630) = -1 ENOENT (No such file or directory)
  195. stat("/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/warnings.pmc", 0x7fff41a3c770) = -1 ENOENT (No such file or directory)
  196. stat("/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/warnings.pm", 0x7fff41a3c630) = -1 ENOENT (No such file or directory)
  197. stat("/usr/lib/perl5/5.8.8/warnings.pmc", 0x7fff41a3c770) = -1 ENOENT (No such file or directory)
  198. stat("/usr/lib/perl5/5.8.8/warnings.pm", {st_mode=S_IFREG|0644, st_size=15879, ...}) = 0
  199. open("/usr/lib/perl5/5.8.8/warnings.pm", O_RDONLY) = 4
  200. ioctl(4, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff41a3c3c0) = -1 ENOTTY (Inappropriate ioctl for device)
  201. lseek(4, 0, SEEK_CUR) = 0
  202. read(4, "# -*- buffer-read-only: t -*-\n# "..., 4096) = 4096
  203. stat("/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/Carp.pmc", 0x7fff41a3c1b0) = -1 ENOENT (No such file or directory)
  204. stat("/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/Carp.pm", 0x7fff41a3c070) = -1 ENOENT (No such file or directory)
  205. stat("/usr/lib/perl5/site_perl/5.8.8/Carp.pmc", 0x7fff41a3c1b0) = -1 ENOENT (No such file or directory)
  206. stat("/usr/lib/perl5/site_perl/5.8.8/Carp.pm", 0x7fff41a3c070) = -1 ENOENT (No such file or directory)
  207. stat("/usr/lib/perl5/site_perl/Carp.pmc", 0x7fff41a3c1b0) = -1 ENOENT (No such file or directory)
  208. stat("/usr/lib/perl5/site_perl/Carp.pm", 0x7fff41a3c070) = -1 ENOENT (No such file or directory)
  209. stat("/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/Carp.pmc", 0x7fff41a3c1b0) = -1 ENOENT (No such file or directory)
  210. stat("/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/Carp.pm", 0x7fff41a3c070) = -1 ENOENT (No such file or directory)
  211. stat("/usr/lib/perl5/vendor_perl/5.8.8/Carp.pmc", 0x7fff41a3c1b0) = -1 ENOENT (No such file or directory)
  212. stat("/usr/lib/perl5/vendor_perl/5.8.8/Carp.pm", 0x7fff41a3c070) = -1 ENOENT (No such file or directory)
  213. stat("/usr/lib/perl5/vendor_perl/Carp.pmc", 0x7fff41a3c1b0) = -1 ENOENT (No such file or directory)
  214. stat("/usr/lib/perl5/vendor_perl/Carp.pm", 0x7fff41a3c070) = -1 ENOENT (No such file or directory)
  215. stat("/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/Carp.pmc", 0x7fff41a3c1b0) = -1 ENOENT (No such file or directory)
  216. stat("/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/Carp.pm", 0x7fff41a3c070) = -1 ENOENT (No such file or directory)
  217. stat("/usr/lib/perl5/5.8.8/Carp.pmc", 0x7fff41a3c1b0) = -1 ENOENT (No such file or directory)
  218. stat("/usr/lib/perl5/5.8.8/Carp.pm", {st_mode=S_IFREG|0644, st_size=8840, ...}) = 0
  219. open("/usr/lib/perl5/5.8.8/Carp.pm", O_RDONLY) = 5
  220. ioctl(5, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff41a3be00) = -1 ENOTTY (Inappropriate ioctl for device)
  221. lseek(5, 0, SEEK_CUR) = 0
  222. read(5, "package Carp;\n\nour $VERSION = '1"..., 4096) = 4096
  223. read(5, "an not get %CarpInternal or %Int"..., 4096) = 4096
  224. read(5, "need to (for Safe compartments)\n"..., 4096) = 648
  225. read(5, "", 4096) = 0
  226. close(5) = 0
  227. stat("/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/Exporter.pmc", 0x7fff41a3c1b0) = -1 ENOENT (No such file or directory)
  228. stat("/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/Exporter.pm", 0x7fff41a3c070) = -1 ENOENT (No such file or directory)
  229. stat("/usr/lib/perl5/site_perl/5.8.8/Exporter.pmc", 0x7fff41a3c1b0) = -1 ENOENT (No such file or directory)
  230. stat("/usr/lib/perl5/site_perl/5.8.8/Exporter.pm", 0x7fff41a3c070) = -1 ENOENT (No such file or directory)
  231. stat("/usr/lib/perl5/site_perl/Exporter.pmc", 0x7fff41a3c1b0) = -1 ENOENT (No such file or directory)
  232. stat("/usr/lib/perl5/site_perl/Exporter.pm", 0x7fff41a3c070) = -1 ENOENT (No such file or directory)
  233. stat("/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/Exporter.pmc", 0x7fff41a3c1b0) = -1 ENOENT (No such file or directory)
  234. stat("/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/Exporter.pm", 0x7fff41a3c070) = -1 ENOENT (No such file or directory)
  235. stat("/usr/lib/perl5/vendor_perl/5.8.8/Exporter.pmc", 0x7fff41a3c1b0) = -1 ENOENT (No such file or directory)
  236. stat("/usr/lib/perl5/vendor_perl/5.8.8/Exporter.pm", 0x7fff41a3c070) = -1 ENOENT (No such file or directory)
  237. stat("/usr/lib/perl5/vendor_perl/Exporter.pmc", 0x7fff41a3c1b0) = -1 ENOENT (No such file or directory)
  238. stat("/usr/lib/perl5/vendor_perl/Exporter.pm", 0x7fff41a3c070) = -1 ENOENT (No such file or directory)
  239. stat("/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/Exporter.pmc", 0x7fff41a3c1b0) = -1 ENOENT (No such file or directory)
  240. stat("/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/Exporter.pm", 0x7fff41a3c070) = -1 ENOENT (No such file or directory)
  241. stat("/usr/lib/perl5/5.8.8/Exporter.pmc", 0x7fff41a3c1b0) = -1 ENOENT (No such file or directory)
  242. stat("/usr/lib/perl5/5.8.8/Exporter.pm", {st_mode=S_IFREG|0644, st_size=14419, ...}) = 0
  243. open("/usr/lib/perl5/5.8.8/Exporter.pm", O_RDONLY) = 5
  244. ioctl(5, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff41a3be00) = -1 ENOTTY (Inappropriate ioctl for device)
  245. lseek(5, 0, SEEK_CUR) = 0
  246. read(5, "package Exporter;\n\nrequire 5.006"..., 4096) = 4096
  247. brk(0x6414000) = 0x6414000
  248. lseek(5, 2217, SEEK_SET) = 2217
  249. lseek(5, 0, SEEK_CUR) = 2217
  250. close(5) = 0
  251. read(4, ",\n 'void'\t\t=> 90,\n 'y2k'\t\t"..., 4096) = 4096
  252. read(4, "x00\\x00\\x20\\x00\\x00\\x00\\x00\\x00\\"..., 4096) = 4096
  253. read(4, " $mask = ${^WARNING_BITS} ;\n\n "..., 4096) = 3591
  254. brk(0x6435000) = 0x6435000
  255. read(4, "", 4096) = 0
  256. close(4) = 0
  257. read(3, "", 4096) = 0
  258. close(3) = 0
  259. open("test.out", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
  260. ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff41a3ca10) = -1 ENOTTY (Inappropriate ioctl for device)
  261. lseek(3, 0, SEEK_CUR) = 0
  262. fstat(3, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
  263. fcntl(3, F_SETFD, FD_CLOEXEC) = 0
  264. time([1330767532]) = 1330767532
  265. rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
  266. rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
  267. rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
  268. nanosleep({1, 0}, {1, 0}) = 0
  269. time([1330767533]) = 1330767533
  270. time([1330767533]) = 1330767533
  271. rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
  272. rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
  273. rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
  274. nanosleep({1, 0}, {1, 0}) = 0
  275. time([1330767534]) = 1330767534
  276. time([1330767534]) = 1330767534
  277. rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
  278. rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
  279. rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
  280. nanosleep({1, 0}, {1, 0}) = 0
  281. time([1330767536]) = 1330767536
  282. time([1330767536]) = 1330767536
  283. rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
  284. rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
  285. rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
  286. nanosleep({1, 0}, {1, 0}) = 0
  287. time([1330767537]) = 1330767537
  288. time([1330767537]) = 1330767537
  289. rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
  290. rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
  291. rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
  292. nanosleep({1, 0}, {1, 0}) = 0
  293. time([1330767538]) = 1330767538
  294. time([1330767538]) = 1330767538
  295. rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
  296. rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
  297. rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
  298. nanosleep({1, 0}, {1, 0}) = 0
  299. time([1330767539]) = 1330767539
  300. write(3, "0\n1\n2\n3\n4\n5\n", 12) = 12
  301. close(3) = 0
  302. exit_group(0) = ?
从上面我标成红色的sleep前的操作来看,每次sleep前其实没有打印任何内容到描述符3。而且最后才一次性打印到3的。
我们对前面的脚本稍微做修改后

  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use IO::Handle;
  5. open LOG,">test.out" or die "open file failed\n";
  6. LOG->autoflush();
  7. foreach my $k (0..25)
  8. {

  9.         print LOG ($k,"\n");
  10.         sleep(1);
  11. }
这次会发现每次都割1秒会直接输出了吧。具体的原因google "autoflush + perl"就知道了。

其实也可以直接使用syswrite来做
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. open LOG,">test.out" or die "open file failed\n";
  5. foreach my $k (0..25)
  6. {
  7.         syswrite(LOG,"$k\n",1024);
  8.         sleep(1);
  9. }





阅读(2501) | 评论(0) | 转发(0) |
0

上一篇:文件对比

下一篇:也说说rewrite

给主人留下些什么吧!~~