Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

2
  • Pointless use of grep and invoking awk. Wow. While this might work for illustration (on Linux; I don't know how many other OSes have a /proc, let alone /proc/self/status with the same format), you'd be a lot better off not using both grep and awk at least. For a start, try pid_var=$(awk '/^Pid:/ { print $2 }' /proc/self/status) instead. Starting awk is a fairly heavy operation; I learned this from experience myself piping through awk to do some string manipulation very much like this inside a tight shell script loop. There are often better ways. Commented Nov 25, 2013 at 8:39
  • Surely their must be BETTER ways. Thanks for pointing out. I was just demonstrating here that whatever questioner is looking for is possible. Script optimization was not considered here Commented Nov 25, 2013 at 9:25