![]() |
|
![]() |
| I answered a question once with a rather simple O(n) solution:
https://stackoverflow.com/questions/10865483/print-results-i...
Am I missing anything, are there any glaring bugs? I don't see this as a particularly difficult problem. |
![]() |
| My answer in an interview was “exec Python”. Then you can call all the posix functions you need without launching separate commands.
This went over quite well. |
![]() |
| > Here is what people have been saying about ctypes.sh:
"that's disgusting" "this has got to stop" "you've gone too far with this" "is this a joke?" "I never knew the c could stand for Cthulhu." |
![]() |
| You can calculate a cpu% from the tick information (uticks,kticks,sticks) in /proc/[pid]/stat. I've done it once in a script after spending considerable time reading the manual of proc. |
![]() |
| Would exiting the ssh session not free up the pid again? Also yes, I meant `reboot` not `restart`, and I always forget its only shutdown that needs the `now`, not reboot |
![]() |
| Re sub processes, genuinely curious, how do
and
work? |
![]() |
| This is actually in the POSIX standard for the shell.
"The redirection operator:
"shall duplicate one output file descriptor from another, or shall close one. If word evaluates to one or more digits, the file descriptor denoted by n, or standard output if n is not specified, shall be made to be a copy of the file descriptor denoted by word; if the digits in word do not represent a file descriptor already open for output, a redirection error shall result; see Consequences of Shell Errors. If word evaluates to '-', file descriptor n, or standard output if n is not specified, is closed. Attempts to close a file descriptor that is not open shall not constitute an error. If word evaluates to something else, the behavior is unspecified."https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V... |
![]() |
| [[ is a keyword, and exec is a builtin. With the {name}< syntax, exec is opening a file descriptor and assigning it's numerical value to $name, and {name}>&- closes it |
![]() |
| Necessarily, as this is the kind of API (a file system with a well-defined structure) that the kernel exposes for querying/providing that kind of information :) |
![]() |
| > What if you're ssh'd into a machine, you're in your trusty bash shell, but unfortunately you cannot spawn any new processes because literally all other pids are taken. What do you do?
A long ago for fun I created an interactive website to explore this type of scenario. https://oops.cmdchallenge.com |
![]() |
| Izabera is one of the gurus in #bash@libera (formerly freenode).
I love all those gurus. They've taught me so much over the past decade. |
![]() |
| That's some pretty clean bash. In my experience most bash code is badly written and inefficient, but this is a good example of code that isn't. |
> # this one function looks simple but it took so fucking long
Heh. I can't count how many times I've written a column-aligning functions in various programming languages, and each time it is a pain. And it sounds simple in my head - just get max-length of each column, and add spaces up to the next multiple of tab-size.
But even in Python with f-strings and all the fancy padding stuff it has, it is ends up a convoluted, unreadable mess:
Even while writing this code for the comment for the hundredth time, I've had to fix at least 5 bugs! Truly horrible.