Solving real-world problems with Linux's proc filesystem(blog.ksplice.com)
blog.ksplice.com
Solving real-world problems with Linux's proc filesystem
http://blog.ksplice.com/2011/01/solving-problems-with-proc/
2 comments
[deleted]
http://blog.ksplice.com/2011/01/solving-problems-with-proc/
In zsh the same thing can be accomplished with a more concise syntax:
And, if your process wanted to seek the file (which isn't possible to do with a simple redirection of stdin), you could do:
The main difference is that here, behind the scenes zsh creates and deletes a temporary file with the contents of the stdout of the program between the =().
Another neat thing you can do in zsh to solve the original problem is to create a global alias for stdin:
Then, whenever you typed "STDIN" on the command line, zsh would convert it to "/proc/self/fd/0". Then to make the exact equivalent of the original solution (but one that's easier to remember and type), you could simply write:
A regular alias won't work here, since regular aliases only expand when they're the first part of a command. Global aliases will expand anywhere in the command line. So you just have to be a bit more careful with them.
---
The solution in the "phantom progress bar" section is cute, and a good demonstration of what's possible to do with /proc/$PID/fdinfo, but you could just use a ready made solution like either of these:
http://clpbar.sourceforge.net/
http://www.ivarch.com/programs/pv.shtml