Live data from Hacker News

How to programmatically find out if computer is on

haiku-os.org

121–130 of 197 posts

Re: How to programmatically find out if computer is on

#121

I'm curious if there's any significance in number 0.63739 in this implementation double is_computer_on_fire(void) { return 0.63739; } https://github.com/haiku/haiku/blob/8f16317a5b6db5c672f33181...

I want to build a computer than can run in supercooled conditions, to prove that implementation has a bug.

Re: How to programmatically find out if computer is on

#122
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 ).

Aha. If only the API was "Execute a user-provided function in a context where the computer is guaranteed to be on".

Re: How to programmatically find out if computer is on

#124

Asynchronous JavaScript browser DOM callback API:

Asynchronous is definitely the way to go. I once tried synchronous code. Had to move it to a service worker so as to not bog down the UI, and you don't even want to know what service workers do when the computer is off. Let's just say it's undocumented.

XP's behaviour is interesting in this case. It's one of the few things I actually like about Vista (sue me, I like things about Vista): Vista will abort the shutdown, but XP will hang for an unspecified length of time, when you have an event handler that makes a blocking call like `alert`.

Re: How to programmatically find out if computer is on

#126

I have recently wondered if there is a way to guarantee that a processor is idling. By this I mean, is there a way to ensure another computer has been idle for a time when it promises that it has been. Kind of the opposite of a crypto mining problem.

integrate power consumption seems like an easy answer.

Re: How to programmatically find out if computer is on

#127
These functions are useless since there's no way to know if the function "fails." If the computer is on it returns 1, but if it's off it can also return 1. So if it returns a 1 you don't actually know if it's on (unless you happen to know from somewhere else that the computer is on which at that point why bother calling this function)

Re: How to programmatically find out if computer is on

#128
post #29

Earlier quoted context omitted.

Hmm, it seems like you need to make sure the computer is on before calling this function, or else you run the risk of getting back undefined data. Seems like we also need a function that can be used to tell if the computer is on...

Nah. Just bump that responsibility to the caller, and power supply manufacturer. Have the caller call power_on_computer() first always. This will ensure you always get defined state! ...What do you mean not every power supply manufacturer implements the power_on_computer() function as a NOOP if the computer is already on?!

I know that at least Solaris implemented SIGPWR signal to inform programs of a power failure: https://community.bmc.com/s/article/Inquira-KA334556

Re: How to programmatically find out if computer is on

#129
Why would is_computer_on_fire() return a double and not true/false? Even for a joke function, this seems like bad practice. If the function is named is_state(), I expect a boolean return.

> Returns the temperature of the motherboard if the computer is currently on fire. Smoldering doesn't count. If the computer isn't on fire, the function returns some other value.

Re: How to programmatically find out if computer is on

#130
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".

Is... this not how your WoL works? Hitting the NIC is equivalent to pressing the on button, boots the OS, etc.

I've been using this for years to wake hosts at home when I'm abroad. It's invaluable.

Post reply on HN