Live data from Hacker News

How to programmatically find out if computer is on

haiku-os.org

101–110 of 197 posts

Re: How to programmatically find out if computer is on

#101

Functional programming with monads is the right way to implement this.

Please, can we make it `MonadIO m => m Bool` so that this can work with any IO-like monad and/or monad transformer stacks based off IO? It will also make unit testing much easier.

Re: How to programmatically find out if computer is on

#102
post #60

Since the not-on result is 'undefined', a devilish implementer could return 1 for the off case, just to screw with people. (How could this work in theory? Maybe the computer has a separate watchdog controller board which allows the computer to be turned on and off remotely, and that controller acts as a proxy for the API request.)

Maybe we can forbid the function from returning 1 in the off case. The existence of such a function means that "is this machine running?" is semidecidable - but it's surely not decidable by the machine itself.

Re: How to programmatically find out if computer is on

#104
post #65
post #56

Earlier quoted context omitted.

There's a syscall to check whether the computer is on so just call that before this and you'll be fine

That introduces a time-of-check to time-of-use bug ( https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use ).

Ah, good ole TOCTOU

Re: How to programmatically find out if computer is on

#105

While it is clearly a joke, it has a legitimate use as a syscall that does nothing so can be used to test the syscall process itself [1]. (Its cousin `is_computer_on_fire` is not a syscall.) [1] https://github.com/haiku/haiku/commit/ccaac177f64038c160de6f...

Sure. Of course, one important trick here is that no matter how fast your system call is, not making a system call is just faster. io_uring is an example, as are futexes. So it's worth spending more effort on figuring out tricks to avoid doing the system call than exploiting tricks to shave a cycle or two off the time taken to execute one.

I suppose not checking whether syscalls work would indeed be faster than checking whether they work...

Re: How to programmatically find out if computer is on

#106
post #89

While this is a joke, there are some contexts in which it does make sense to ask whether the computer is on. For instance, most laptops have an embedded controller which runs all the time, even when the laptop is powered off, and manages things like battery charging and the power state. Within that embedded controller, an is_computer_on() function could legitimately return "false".

I've often wondered why WOL is so poorly designed. WOL should be a function of the NIC, completely independent of the OS and capable of returning status codes even if the computer is "off".

Re: How to programmatically find out if computer is on

#108
post #57

I like how it also has support for the ENIAC platform. I kicked my family out of the house so I had room to install the ENIAC. Happy to hear there's an OS I can run on it to get real work done, like posting unfunny jokes for strangers on Hacker News.

It upsets me that this function's interface allows it to describe silly things like "an ENIAC running on a 68000" or "an Apple II running on SPARC". Wouldn't be an issue if C++ supported GADTs.

An Apple II style of computer built around a SPARC would be a fascinating hobbyist platform.
Post reply on HN