2

ps -aux | grep node results in:

root      2814  0.0  0.0   4344     0 ?        S    Mai27   0:00 sh -c node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js
root      2815  0.0  0.0 1358316 1096 ?        Sl   Mai27   0:17 node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js
root      2881  0.0  0.0   4344     0 ?        S    Mai27   0:00 sh -c npx webpack --mode development && node ./build/bundle.js
root      2910  0.0  0.7 1262156 63004 ?       Sl   Mai27   0:47 node ./build/bundle.js

sudo kill 2814 2815 1881 2910 results in permission denied.

I understand that if you run it without sudo that permission denied makes sense if the user is not the one you executed the task with. However, here I have no clue and can someone explain why sometimes a root process cannot be killed with sudo? Does it make any sense? (Especially, because it is just a webpack process of my own project, I don't get it.)

2 Answers 2

8

Since you are on Linux (Ubuntu) -- if sudo kill still gives permission denied then it could be because you're running inside a containerized application (e.g. Snap app) such as VSCode's integrated terminal. Try running sudo kill from another terminal which is not a Snap application, like Alacritty, gnome-terminal, Konsole, etc.


More info:

These types of containerized apps (Snap, Flatpak, etc.) are often restricted by AppArmor profiles which prevent certain system calls (also called "syscalls") from being made.

The kill command works by making a signal() syscall. If the signal syscall is blocked by the AppArmor profile applied to the terminal you are using, then this could result in permission denied.

You could check whether this is happening by checking the kernel logs (run the command dmesg). Example:

[ 6405.232002] audit: type=1400 audit(1658415742.446:231): apparmor="DENIED" operation="signal" profile="docker-default" pid=89218 comm="kill" requested_mask="receive" denied_mask="receive" signal=kill peer="snap.code.code"

The key parts of the error message are: apparmor="DENIED" operation="signal" ... signal=kill. This means that AppArmor is blocking the signal syscall which is attempting to kill the process.

1
  • 1
    This is really useful. I didn't know the VSCode terminal is containerized and it make sense, as there are some commands that refuse to work in the VSCode terminal, but work with no problem in the native terminal. gitg is an example of that. Very useful information!
    – ginger
    Commented Aug 10, 2023 at 10:03
0

Have you tried with -9 switch? Since sudo kill sends -15 (SIGTERM) signal to process to kill itself. Process might not want to do that and therefore -9 (SIGKILL) is needed (if you can't find the underlying parent service to kill).

PS! -9 sends very bruteforce SIGKILL signal, so be careful, it will kill whatever is the underlying process and might result in unresponsive system.

5
  • do you mean sudo kill -s SIGKILL processID ? Permission denied as well. As for SIGTERM as well
    – dragonsoul
    Commented Jun 9, 2019 at 16:19
  • sudo -9 kill 2814 should work. Sometimes for reasons beyond my understanding some interactive shell processes might not respond to kill. Those cases either -9 signal or -HUP has helped sudo kill -HUP 2814. Sighup is an quite old signal for hang up and usually kills unresponsive processes or if daemon then reloads configurations. Just to clarify do you get "Permission denied" or "operation not permitted"?
    – Ajama
    Commented Jun 10, 2019 at 13:53
  • $ sudo kill -9 2993 kill: (2993): Permission denied $ sudo kill -HUP 2993 kill: (2993): Permission denied sudo -9 kill was an error on your side right? Sorry for poor formatting... Don'T know how to do it.
    – dragonsoul
    Commented Jun 11, 2019 at 9:13
  • Yes, my typo. Let's take a look what pstree -p gives us about all those node processes. If you dont have it then package name is psmisc. Just copy the output or add it to you original question. Also use root terminal for this sudo -i for example will give u root terminal session.
    – Ajama
    Commented Jun 12, 2019 at 8:44
  • Hi thanks for your help! however, the process is finally terminated. Unfortunately, my whole laptop with it... Well, it does not charge anymore:-/ So I cannot work with it anymore. However, If somebody else has the issue, we can hopefully find a solution.
    – dragonsoul
    Commented Jun 13, 2019 at 9:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.