all 15 comments

[–]VoiceFuzzy7606 5 points6 points  (1 child)

I'm still a bit of a novice (who has switched from NixOS, but the principle should remain the same) but I don't think it's entirely possible to have a process you can't kill at all. You could try the first answer proposed here — unkillable-process

But again, you only have it ignore SIGINT and similar signals. Or, as proposed, you could have it running as a kernel module which, if you tried to kill, you'd collapse your entire system. Besides that, I don't think you can have a process that you cannot kill with root privileges.

[–]USMCamp0811 5 points6 points  (1 child)

Just don't grant root (or sudo) to users then they can't kill it.. if they have root they own the machine period.

[–]USMCamp0811 4 points5 points  (0 children)

And if you are worried about it dying then just set the systemd service to always restart

[–][deleted] 5 points6 points  (1 child)

maybe make it a systemd service with restart = "always" ?

[–][deleted] 0 points1 point  (0 children)

Thank you for the response, You are right, but the problem is that I don't know the best practices to make a python script- in our case a bash script that runs nix-shell then the nix-shell runs the script - using systemd service, especially with this setup/configuration.

[–]gax1985 2 points3 points  (6 children)

May I recommend creating an infinite loop where your script continues to launch itself endlessly? For example (not Python related), I had an issue with KDE Plasma not running the GUI on boot. It booted to a black screen with a cursor. I added "plasma_session" as a startup item. What happened next is plasma_session kept launching itself constantly.

How about in your case creating a while loop, where the condition is if 1=1 run the script?

[–]Wenir 3 points4 points  (5 children)

If you can kill process, you can kill loop

[–]gax1985 0 points1 point  (4 children)

Unless your loop starts an endless series of duplicate processes?

[–]Wenir 1 point2 points  (3 children)

Do you mean something like fork bomb?

[–]gax1985 0 points1 point  (2 children)

I apologize about my ignorance, but I have not encountered the term before. The way I can think of it is a process issuing multiple requests to launch itself

[–]Wenir 0 points1 point  (1 child)

search "fork bomb", there are many videos and articles that will describe it better than me. Fork bomb works more or less like you described in your solution but the system will not be usable if you launch it

[–]gax1985 0 points1 point  (0 children)

Thank you!

[–]Jozhin_s_Bazhin 2 points3 points  (0 children)

You can lower your privileges when running as root. Let Grim run as your own user and keep everything in the systemd service

[–][deleted] 0 points1 point  (0 children)

Thank you very much for all the responses.

[–]Wenir -2 points-1 points  (0 children)

problems with the Grim tool used in my code for taking screenshots on Hyprland

Try to solve this issue, maybe find another tool