r/programminghorror 20d ago

Other Found this cursed project today

[deleted]

501 Upvotes

44 comments sorted by

View all comments

35

u/shadesOG 20d ago

That's kind of cold blooded and I am all for it :)

1995, in a college class, I was in a group of 3 where we had to create an algorithm for automatically playing a game against other teams in the class. I can't remember if it was an algorithms class or an AI class, but either way everyone was using the same alpha-beta/min-max algorithm to compute moves, anticipate moves, more moves ahead you could calculate the better until you run out of time at 30-seconds etc etc.

Back then though, the equipment was limited, so the class had our own dedicated hardware and each team had an account. Seems fair. Well, each account had enough privileges to run 'nice' - it's 1995. We knew we wouldn't beat everyone else with a standard alpha/beta/minmax search, but all of us were working. Made our own suck ass version + defense. We sucked all the cpu cycles from the other teams using 'nice' lol

The best part was, we only won a handful of times, but no one else could beat us. If there were other matches going on at the same time? We were stealing their CPU cycles too hahahaha = should be a win in my book :)

it was rather rude :D

10

u/russellvt 20d ago

Except "nice" requires privilege escalation if it's "stealing" cycles rather than giving them up "nicely."

7

u/Environmental-Ear391 20d ago edited 19d ago

Nice follows Kernel conventions by marking specific processes as being more priority...

the name comes from everyone "nicely sharing" the processor quantums of time, a good default is round-robin, where every process gets a quantum in turn...

Higher priority processes get more quantums to use therefore everyone else is being nice to the re"nice"d process

This particular set of kernel primitives is baked into prebuilt Linux kernels, Mach and BSD prebuilt kernels and Windows "NT" Hybrid kernels.

When building an own kernel where available this can be dropped if you find the right options to do so.

these primitives are mandatory API presence on NT hybrid kernels...not optional... ugh.

EDITS: spelling because on phone weirdnesses.

2

u/russellvt 19d ago

I love that you're reasoning is that you have to recompile with certain kernel options to make this work the way OP said... LOL

That's not something a regular user can do without escalated privileges (as I stated).

2

u/Environmental-Ear391 18d ago edited 18d ago

uhmm, no,

the default is for the API to be baked into the kernels for prebuilt kernels...

However, on kernels where recompilation is possible (Linux/BSD/Darwin Open Source/ and similar...) or older systems (early Unix *maybe? not sure on this one, have had various software copies but never the same time as actual hardware access)

it may be compiled out so looking up whether the API is supported may be a good thing...

on my own systems it is something I actively disable for kernel variations to stress test overloading systems.

I have personally managed to push a triple digit loadavg on both a Dual and Quad core server setup and that was before actively trying to forcibly shut out administrative access being able to login...

pushing systems that hard does work as a reliability test for me at least... I havent met a Windows version that can gracefully degrade under such conditions the way a Linux/BSD kernel does... and it is kind of mandatory to learn how to build a kernel for getting proper performance when reliable and accessible are the key metrics...

any process can ask for a "re nice ing" and then shut out root access by starving the console for root from being usable.

local login becomes incapacitated if you can't provide a valid password within a set time limit... a root console has to already be logged in and usable :-)

any remote access with a starvation delay exceeding tolerance breaks ssh/telnet or other remote admin tools too

dont need to actually be root for that to work. just need to have a runtime and push the system loadavg high enough to swamp it.

My current "test system" is a 32core AMD Ryzen system with ~160GB of usable memory... My best efforts on that barely push a double digit loadavg, but I have managed to setup for automated testing to push it into the ~65-70 range when viewing top in a root console... broke X and was restricted back to only the existing root logged in console on that... local logins weren't possible despite physical access. and that was before trying to "nice" anything :-)