List all processes I can kill, so I can kill them

0

I need to figure out all the processes I can kill as my user (without privileges), so I can kill them. how do I do that? I just wanna kill everything I can.

SoniEx2

Posted 2019-06-23T15:57:04.680

Reputation: 127

What is the operating system you are running? – Nimesh Neema – 2019-06-23T15:59:42.210

I'd like to do it in the most posix compliant way. – SoniEx2 – 2019-06-23T16:01:01.277

That's helpful information. Please add it to the question. The command options may vary between OS. It would help if you can mention all the OS that you use. – Nimesh Neema – 2019-06-23T16:02:16.930

Answers

1

The kill() syscall accepts the PID -1 to specify "all possible processes".

If pid equals -1, then sig is sent to every process for which the calling process has permission to send signals, except for process 1 (init), but see below.

[...]

POSIX.1 requires that kill(-1,sig) send sig to all processes that the calling process may send signals to, except possibly for some implementation-defined system processes.

From command line, use kill -TERM -1. (The signal name must be explicitly specified, otherwise the "-1" will be misinterpreted as specifying SIGHUP rather than specifying the process ID).


To enumerate all killable processes:

  1. Find out your OS-specific method to enumerate all processes that exist. There is no POSIX-standard C API for doing so.
  2. For every process ID, send the signal 0 (dummy signal used for permission checks only). If you get zero, you're allowed to kill that process; if you get -EPERM, you're not.

Note that doing this in order to subsequently kill all those processes is a waste of time, because you can just send the actual signal as soon as you know the PID. (Not to mention that it depends on non-POSIX features for process enumeration.)

user1686

Posted 2019-06-23T15:57:04.680

Reputation: 283 655