Output file descriptor of sml is closed




















Learn more. How can I check to see if a file descriptor was closed? Ask Question. Asked 8 years, 2 months ago. Active 3 years, 1 month ago. Viewed 14k times. Add a comment. Active Oldest Votes. The easiest way is probably to just check the return value of your first close. In single-threaded code only, where nothing can recycle an fd between close and check : If you wish to check whether a file descriptor is valid afterwards then you can use any function that consumes a file descriptor and check it's error code.

Peter Cordes k 41 41 gold badges silver badges bronze badges. Sergey L. SteveJobs: Each of those methods are dangerous in a multi-threaded environment, as the file descriptor in question might very have been recycled by another thread since it has been closed the last time.

Active 8 years, 6 months ago. Viewed 8k times. Thomas Calc Thomas Calc 2, 2 2 gold badges 28 28 silver badges 54 54 bronze badges. This seems like something you could test? You're right, I initially had no idea how to detect that it's closed, but now I can think of something, and Jiri Patera also gave an option in his answer.

Add a comment. Active Oldest Votes. Jiri Patera Jiri Patera 3, 1 1 gold badge 18 18 silver badges 14 14 bronze badges. Thanks, this answers a part of my question.

The remaning part is that if you create more FileInputStream objects based on your fd , when does fd become invalid? If you close fd[0] in parent and also in child there is from nowhere you can read from the pipe, in the reverse case if you close fd[1] in both the processes you cannot write into pipe, So we close the read descriptor in one process so that the process can only write and the other process will close write descriptor which will enable the process to only read from pipe.

Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Closing pipe file descriptor in C Ask Question. Asked 7 years, 10 months ago. Active 7 years, 10 months ago. Viewed 20k times. Improve this question. Josh Durham 1, 1 1 gold badge 16 16 silver badges 27 27 bronze badges. Xufeng Xufeng 5, 6 6 gold badges 22 22 silver badges 28 28 bronze badges.

Each fd is one end of the pipe. Add a comment. Improve this question. Ryan Kavanagh. Ryan Kavanagh Ryan Kavanagh 1 1 silver badge 7 7 bronze badges. Add a comment. Active Oldest Votes. This is not a complete answer. I tried to run strace sml nwe.

Improve this answer. Simon Shine Simon Shine Thanks Simon! I ran it through strace and found that though the second child was writing to some file descriptor N and the parent's stdin was set to N by dup2, the parent never actually read any messages the second time around. I'll post a more detailed analysis and how I fixed it tomorrow. My initial attempt consisted of Creating a pipe Setting stdout of the child to be the write end of the pipe Setting stdin of the parent to be the read end of the pipe This didn't work the second time around, perhaps because of some race condition running it under strace -f meant that we could see the second child writing to the write end of the second pipe, but the parent never managed to read from the read end of the second pipe.



0コメント

  • 1000 / 1000