[opensuse] Re: Curiosity really can kill -- or at least slow you down quite a bit...
David C. Rankin wrote:
Listmates,
A caution to the curious. Never.. Ever... use a for loop and cat to attempt to look at *all* the values for a process in /proc. Bad things happen on 11.0 (probably all versions).
I wanted to look at the values for a bash shell running in konsole as process 24214 so I did:
for i in $(find /proc/24214 -type f); do echo -e "$i\t$(cat $i)"; done
The system slowed to a crawl...
There are binary files below /proc. Some of them may produce very long output, e.g., pagemap on my system is 26MB long, which surely would break my terminal. It's typically not a good idea to output them with cat & echo. Actually, writing this shell command that way is *never* good style. You expand the output of a command into a shell string just to output it. That's nonsensical, you might just echo -n your tab and then call cat. (Both -e and -n are bashisms, btw, and are not necessarily portable to other shells. From my quotes file, a Usenet snippet from Larry Wall: ------------- Drew Mills writes: : A contest to see who could write the most useful script that could : actually be used in the most languages *as is* [...] I've written some scripts that work in 582 different languages, all of them named sh. ------------- ) Joachim -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Joachim Schrod Email: jschrod@acm.org Roedermark, Germany -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Joachim Schrod wrote:
David C. Rankin wrote:
Listmates,
A caution to the curious. Never.. Ever... use a for loop and cat to attempt to look at *all* the values for a process in /proc. Bad things happen on 11.0 (probably all versions).
I wanted to look at the values for a bash shell running in konsole as process 24214 so I did:
for i in $(find /proc/24214 -type f); do echo -e "$i\t$(cat $i)"; done
The system slowed to a crawl...
There are binary files below /proc. Some of them may produce very long output, e.g., pagemap on my system is 26MB long, which surely would break my terminal. It's typically not a good idea to output them with cat & echo.
Actually, writing this shell command that way is *never* good style. You expand the output of a command into a shell string just to output it. That's nonsensical, you might just echo -n your tab and then call cat. (Both -e and -n are bashisms, btw, and are not necessarily portable to other shells. From my quotes file, a Usenet snippet from Larry Wall:
------------- Drew Mills writes: : A contest to see who could write the most useful script that could : actually be used in the most languages *as is* [...]
I've written some scripts that work in 582 different languages, all of them named sh. ------------- )
Joachim
Thanks Joachim, I used the expansion because I knew the number of files wasn't a concern. I know I could have just used -print0 | xargs -0 echo 'bla bla...'; and in hind site, it would have been better, but I don't think it made any difference in this case because the number of files was just about 100. As for the -e bashisms, call me lazy but I just wanted to put a quick tab in between the file name and its contents. The binary output was most likely the cause of the fun I experienced. On that we are both in agreement;-) -- David C. Rankin, J.D.,P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (2)
-
David C. Rankin
-
Joachim Schrod