Nuance deadlock on console output redirection.
来源:互联网 发布:linux安装下载好的内核 编辑:程序博客网 时间:2024/05/21 22:34
I helped a colleague on debugging the program she wrote. It's so weird that if we invoke the program directly by cmd.exe, it executes perfectly. However, if we invoke it from another program wrote by she, both programs just hung there.
I went through the code and there is nothing special. So I use Windbg attached the the child process and printed out call stack of every thread, I saw main thread was blocked on NtWriteFile. So I checked the handle used by NtWriteFile, but there was not much info useful. So I went ahead checked all critical sections but it seems there was no dead lock in the child process. I made a mistake here: I did not check the parent process to see where it's blocked!
Since nothing found via debugger, I went back to look at the codes and I see something like this in the parent process' code:
Process cp = Process.Start(CurrentCommand);cp.WaitForExit();RedirectStandard(cp);
Wow, seems there is something wrong. You can see that parent process is waiting for child process to exit so that it can read it output. What if the child process' output buffer is full before it finishes its job and exit?
Things become clear here. After changing the sequence, the hung issue gone. After that I seached the web for the buffer size, I did not find out the exact size of the buffer, but I did find out someone encounters the similar issue before, however, he/she used a different approach.
Ref link:
http://stackoverflow.com/questions/139593/processstartinfo-hanging-on-waitforexit-why
Addtional Notes:
If you only need to redirect only one of stdout / stderr, it's fine to simply switch the sequence of the wait for exit and the redirection. But if you need to redirect both of them, then you will need to implement an async redirection pattern, as the link provided.
- Nuance deadlock on console output redirection.
- Redirection on input/output.
- MFC output on Console
- [Encoding]How to do proper encoding output redirection on cmd.exe?
- Standard Input and Output Redirection
- hpux (console is on a serial device,no further output will appear on this output device)
- Silence output of return object in IRB console on windows
- Linux - Redirection of Standard output/input
- HP-UX开机提示console is on a serial device,no further output will appear on this output device
- .net console output sample
- omap35 出现 No more output is seen on the console after "Starting Kernel..." 调试信息
- 出现 No more output is seen on the console after "booting the kernel" 调试信息
- Redirection
- Piping and Redirection,output,Reading from STDIN in script(Linux)
- Deadlock
- deadlock
- Deadlock
- Deadlock
- MongoDB Map Reduce速度提升20倍的优化宝典
- Java代码质量检测评估工具-Findbugs
- HBASE SHELL 常用命令
- 记一类DP问题!
- 黑马程序员--------集合
- Nuance deadlock on console output redirection.
- 查看电脑综合信息命令
- ajaxJSON数据传递交换/ajaxJSON传对象/解析对象,JAVA封装成对象传到jsp/html页面, ajax中使用JSON
- Junt4 动态代码测试
- 网站优化前期工作是很重要的
- 有关回文字符串
- Android 学习 之 Looper Handler Thread Messahe 多线程
- 类模板与模板类
- C#如何把控件的边框角画为圆弧