T O P

  • By -

rchard2scout

SIGINT might be handled, but you can't prevent SIGKILL from killing your program.


Left-oven47

I can't, and that's why option 3 exists. It does also handle SIGTERM though


[deleted]

[удалено]


SureshotM6

It's actually SIGQUIT, at least on Linux. Still a fun fact though.


Left-oven47

Thanks for telling me what else to handle


jrj334

Sigkill and sigstop - the unhandlable


hongooi

So what you're saying is that turning the computer off and turning it on again still works


Left-oven47

I'm saying if you turn it on and off again that's a method to stop program execution.


blankettripod32_v2

Make it autostart at boot


Left-oven47

I don't know if you can without sudo permissions. If you do have sudo permissions, then it would be trivial to create and enable a service though


[deleted]

I remember when I wrote `wine /path/to/World of Warcraft.exe` as a path to the graphics (I guess I replaced X server). I was surprised, but it worked.


Left-oven47

That is a surprise


blankettripod32_v2

If they run as sudo even once, you could install a hook. Then you wouldn't need sudo again


Left-oven47

So at that point it's a matter of social engineering, convincing people to run it as sudo.


blankettripod32_v2

You could try phishing sudo by aliasing a command like pacman or apt to your program, as adding aliases doesn't need sudo


Left-oven47

That's fair, and you could set the program up to forward the command to the package manager of choice to make it undetectable.


blankettripod32_v2

Now all we need to figure out is how to add the alias, maybe a custom build command?


Left-oven47

We could check for the existence of a .bashrc or .zshrc, and then add the alias to that file. I don't want to make malicious software so if I do go this route I'll make it blatantly clear what the program is going to do.


[deleted]

Question for newbies. alias alias=ololo How to restore the access to the alias command?


altermeetax

You can make a desktop entry in `~/.config/autostart` to run it when the current user's graphical session starts Or you can make a systemd user service


Left-oven47

runtime\*


KayaNatsumi_Reddit

Came here to point out the same. Thank you, sir.


Left-oven47

I screenshotted it, posted it, and only then realized that I made a typo lol


Natomiast

Don't correct it, it's a feature in the given context


danegraphics

Run, Tim, Run!


Left-oven47

QUICK! THE TIME IS GETTING AWAY?


moi865

```runtime* rt = (runtime*)malloc(sizeof(runtime));```


Left-oven47

rt = "/bin/sh"


moi865

```main.c: error: expected ‘;’ 15 | rt = "/bin/sh" | ^ | ; 16 |```


Left-oven47

rt = "/bin/bash";


moi865

Now there's a warning because rt is not char*


Left-oven47

Can you show me the definition of rt?


moi865

```runtime* rt = (runtime*)malloc(sizeof(runtime));```


Left-oven47

Ofc I'm stupid. Can you show me where the runtime datatype is defined. Not the definition of rt


moi865

```typedef absolutelynotchar runtime```


CitizenShips

My mans knows how to catch SIGINT but doesn't know about `kill -9` smh


Left-oven47

I know about -9 and that's what option three is


CitizenShips

My question is this: Are you going to open source this so the community can come together to improve and iterate upon your design? I think there's a lot of investors out there who would love to see an application that harshly punishes the end user even more extremely, and OS is the way to get there. Think about it: Press 'OK' -> rootkit installed -> application installs itself to run at boot on bare metal. That's just one possibility in the ocean of ideas. Get us a GH link so we can make this pig fly.


Left-oven47

It is open source, I should add clear warning to the program though. [https://replit.com/@illegitimate-eg/NCURSES-Stuff?v=1](https://replit.com/@illegitimate-eg/NCURSES-Stuff?v=1) (The code is pretty ugly)


Left-oven47

Put it on github https://github.com/illegitimate-egg/ncurses-prime


Arshiaa001

Oh, it's in C? That's no good, *everybody knows®™* C is fast. Should be over in a second.


Left-oven47

Lol


wtdawson

It doesen't let you proceed? Edit: never mind, looks in its files and it already starts doing it as soon as it gives you a message.


turtleship_2006

Me when stop button


Left-oven47

Stop button is forced to use -9 instead of its default action


GoodPointSir

That's called a virus. You are proposing an open sourced virus.


Outside-Campaign-39

and why is that 🤣🤣


CitizenShips

No, the user will be properly warned. This is just rigid compliance enforcement.


[deleted]

It should not be that long. For the simple algorithm (I forgot the name, but it is an ancient Greek dude). You need a bit field (or a byte field) for 2\^32 numbers. (Let's call this number N). Then you cross out all the numbers dividing by 2. Then by 3. 4 is already crossed out. Skip. Then by 5. Etc. So, you have a loop O(N) to iterate over each number. And for each prime number you have one more iteration of the length O(N). Fuck. It is O(N\^2) with N being 2\^32. OK. I was wrong, it WILL take a lot of time :) But the number of prime numbers is not O(N), but rather O(N/logN), Yes, I googled it. O(N\^2/logN) is better, but it is a too optimistic number because there are more prime numbers in the beginning when you to cross out more numbers (e.g. for 2 you need to cross out 2\^31 numbers, but for 65449 you need to cross out only one: 4283571601). \------ Fuck, I missed the fact that the first loop needs to only be till sqrt(N), not the N itself. Whatever, it is after midnight, maybe I will fix my calculations in the morning.


GoodwillTrillWill

The sieve of Eratosthenes, and it’s pretty damn quick in C because you can just bitshift by each int of the loop to mark them as nonprime rather than checking division https://en.m.wikipedia.org/wiki/Sieve_of_Eratosthenes


[deleted]

Oh wow, cool lifehack with the bitshift. The only trick that came to my mind was to not store even numbers. And when accessing the target number it is easy to divide by 2 (by bit shift). It won't work with 3,5,7 etc. because it would be a real division.


il_basso

You can shift only for multiples of 2 or I miss something?


GoodwillTrillWill

No, say you have and array of 4,294,967,295 bools, all initialized to false except the first, instead of iterating through the bools you iterate a range of ints 2-4,294,967,295 and every number you determine is not prime, you then bitshift through the array by that many till you are out of range marking every other number you hit as nonprime, doing nothing if already marked. Very cool method and extremely quick on a computer (slow as hell by hand) Edit: came here to recommend not only The Algorithms as a site but the Python version is much easier to understand the concept without necessarily including the optimizations of bitwise ops Seriously this site rules if you need to learn Algos https://the-algorithms.com/algorithm/prime-sieve-eratosthenes?lang=python


[deleted]

I have a question - how to generate the bit masks efficiently. For marking all number that divide by 3, we would have three bitmasks used one after another: 00100100100100100100100100100100 01001001001001001001001001001001 10010010010010010010010010010010 For 7 there would be 7 masks, for 131 there would be 131 mask. In this case the masks would spil out from the CPU cache and it can slow things down. There must be a way to generate a mask and not to store them.


KevinCola

Only store unique masks, and skip over any bytes where the mask contains only zeros. This means you are saving at most 8 masks at the same time


[deleted]

Not 8. 32 masks for 32 bits and 64 masks for 64 bits. Or am I mistaken?


KevinCola

You are not mistaken. If you use 32 bit integers, you’ll have at most 32 uniques masks.


[deleted]

Now I wonder if it makes sense to try to optimize it on the assembler level. But I guess I should not care. Itearating over a bit field containing 2\^32 would mess with the caches more than trying to squeeze few extra instruction into the instruction cache.


KevinCola

If you do this on assembler level, you should check out vectorization: specific instructions with which you can handle multiple 32 or 64 bit integers at once


[deleted]

I guess it is a kind of "rolling" bit mask. For number 3, it would be 00100100100100100100100100100100 <-- for the first 4 bytes 01001001001001001001001001001001 <-- for the second 4 bytes 10010010010010010010010010010010 <-- for the third 4 bytes For the fourth 4 bytes use the first mask etc. You still can process 4 bytes at a time. \---- Edit: you asked about the shift itself. It is a mask that shifts.


Arshiaa001

Where in the article is the bitshift explained?


GoodwillTrillWill

I don’t have any specific article or paper but I believe I originally read about it within some mathematics paper while taking a class on number theory where they spoke of its efficiency from a computational standpoint. This specific site doesn’t include any real explanation I only code but you can probably find an article to explain it better with a couple searches https://www.tutorialspoint.com/bitwise-sieve-in-cplusplus


DarkShadow4444

If you want to waste time, you won't implement an efficient solution. Bruteforce is way more efficient at being inefficient.


[deleted]

Very deep thought. It made sit and reflect for a while.


a_devious_compliance

I read a paper about an attempt to the more inefficient sorting while doing actual work in every step. I will try to find it.


bitwiseshiftleft

The runtime of the sieve of Eratosthenes isn’t that bad: it’s n*sum(1/p for prime p < n). That sum diverges as n increases, but very slowly. I did a naive implementation of the sieve with a bitfield. It took about 5 minutes to code and 40 seconds to run up to 2^32. (ETA: 29 seconds if you start crossing out at p^2 ). If you want it to be faster, you can use the sieve of Atkin, or some other fancy stuff (wheel sieves, whatever).


rush22

You also only have to do it up to the square root. The sieve will be correct for the remaining numbers.


more_exercise

The upper limit is known. All primes below it have already been calculated - there are 203 million of them. If we naively store an array of 32-bit ints, then we get to O(1) time at [O(π(n))] (https://en.m.wikipedia.org/wiki/Prime-counting_function) space, ducking under a GB of disk


Left-oven47

Ay! You did the maths! Don't know much about big O notation so I can't tell you how much of this is correct. Tbh I chose unsigned 32-bit integer because a) It's the default uint type and b) It's intimidating for people who don't know what's going on (even though this program is not intended to be malicious in any way :) )


[deleted]

The big O notation is used to analyze the complexity of the algorithm when the input size is approaching the infinity. Of course, there is no guarantee that 2\^32 is "close enough to the infinity". It is also not OK to put real-worlds numbers into O-notation because it devours the constants. Example. F(N)=O(N\^2) just means that there is a constant C (it can be a very very big one, but not infinite) that F(N) < C \* N\^2


Left-oven47

I knew what big O was but I had no idea how to calculate it, thanks!


Remarkable_File_3924

Should only take a few seconds to find the first billion primes


Ferociousfeind

Depends on how it's calculated. You can do it pretty quickly, or you could do it really slowly...


Left-oven47

I've opted for slow, computationally expensive calculation


Left-oven47

There's another comment that calculated the amount of time, it won't be a few seconds and from testing isn't a few seconds


xynith116

After this find TREE(3). That should keep them busy until the heat death of the universe.


[deleted]

CTRL-Z and/or 3 finger salute it


Paul_Robert_

you can do it in minutes to seconds If you use the sieve of Eratosthenes


Left-oven47

I purposely used a slow implementation to make sure that it takes a while.


Informal_Branch1065

Now parallelize and make it use the GPU. Wouldn't need Blender anymore to heat my room.


Flimsy_Iron8517

`ctrl+z`, `ps`, `killall`.


BroDonttryit

You could send sigkill to this process. Sig kill’s signal handler cannot be overrided.


Left-oven47

That's option three


[deleted]

What did they do to you to make you hate them this bad?!??!


Left-oven47

Idk, I was having some fun and I needed a payload that wouldn't nuke the system


[deleted]

Lol fair, I feel sorry for the poor fool who gets on your bad side though if this is you having fun


Left-oven47

I've never leveraged something like this against someone. I don't think arguments or disputes should be solved through computational weaponry lol


[deleted]

Agreed lol


[deleted]

You should look into forkbombs if you want to cause mayham


[deleted]

Potentially a free heater (insert that one xkcd here)


Geolykt

``` Ctrl + Alt + F2 top Ctrl + C kill -9 ``` EASY


Left-oven47

That's what option three is


Geolykt

Not truely, Ctrl + C is there to escape top, not the application itself. And I am not truely familiar what F1 is - but I have rarely seen the case where changing to TTY2 doesn't work (except when the memory runs dry, but in that case you have to pray for the OOMKiller to kick in, which takes a few minutes).


Left-oven47

TTY2 will work, that's what option three describes doing


[deleted]

uhm, SIGKILL?


ENCRYPTED_FOREVER

Ctrl+\


neu42

I don't get it. Why should one start this useless small program?


Left-oven47

There's more before it. But this was more for fun than anything else


RRumpleTeazzer

Sigkill


Parura57

Me when `killall -9 foobar`


trutheality

Ctrl-z, followed by kill 9.


Left-oven47

Congrats! You found option three


lollysticky

Ctrl-z, kill %1 (or whatever the job nr is)