Kill -9 -1 combination

Good morning, In a Production environment ive seen this command that kills processes

kill -9 -1

Because i am in a production environmet i can not execute this comamnd, so i would like to know what is the difference for the conventional kill -9 PID ?
Thanks a lot

man kill :

Your shell may have its own version of kill which may behave slightly different; pls. verify upfront.

I think knowing a bit more about your production environment could help us guess the purpose:

  • what is the architecture and OS?
  • What kind of production are we talking about?

As for the rest RudiC has made it clear what is normally expected... so replying to RudiC's request would be cool too and will provide us better understanding

never EVER run this command as root - as it will inevitably cause your system to restart.
If run as normal user, it will in all likelyhood kill all processes running as this user at once - including the user shell the user is in (so you will be kicked out)

1 Like

Good afternnon:

Thank you very much all of you for your help

This is 1 of 4th web application node using apache as a webserver, and as a Production env it receives all the htpp traffic from internet throuh a load balancer called (F5 -A10) and by a java process called germ.jar open sockets to port 89xx (load balancer), so below is the information:

$ /bin/bash --version
GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
$ uname -a
Linux serverbam04.nh 4.1.12-124.15.2.el7uek.x86_64 #2 SMP Tue May 22 11:52:31 PDT 2018 x86_64 x86_64 x86_64 GNU/Linux
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-b10)
OpenJDK 64-Bit Server VM (build 25.171-b10, mixed mode)

webserver apache

EE-plus-7.0.2/lib/openejb-javaagent.jar -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -classpath /usr/share/tomEE-plus-7.0.2/bin/bootstrap.jar:/usr/share/tomEE-plus-7.0.2/bin/tomcat-juli.jar -Dcatalina.base=/usr/share/tomEE-plus-7.0.2 -Dcatalina.home=/usr/share/tomEE-plus-7.0.2 -Djava.io.tmpdir=/usr/share/tomEE-plus-7.0.2/temp org.apache.catalina.startup.Bootstrap start

The reason why i asked whad does kill -9 -1 does is because our web application provider suggested every time we shut down the app, i will have to run this command to make sure all session are cleaned, but i didnt know how powerful or dangerous this command will be

some time ago the user med has 1615 processes because a shell that runs every 5 minutes got stuck and blocked the node, and we contact aour System Administrator but these processes could never get killed and this node had to be started

med+ 32737     1  0 14:49 ?        00:00:00 /bin/bash /app/perm/backend/check_port_process/CHECK_PORT_PROCESS_MAIN.sh
 32742     1  0 13:15 ?        00:00:00 /bin/bash /app/perm/backend/check_port_process/CHECK_PORT_PROCESS_MAIN.sh
$ ps -fu med|wc -l
1615

kill command

ps -fu med | grep -v grep | awk '{print $2}' | xargs kill -9

Thanks again for your help

Might be a candidate for the pkill command?

Yes pkill -u med && sleep 5 && pkill -9 -u med would be a smart command (the "friendly" kill first).

Some OSes - like AIX - by default do not have a pkill command :slight_smile: Someone might have installed it from somewhere but its not native so do not assume it exists on your host.

If you are logged in as the user med, and you want everything down that this user runs, kill -9 -1 is a pretty safe method. But only run it when the application stop script left things running. So wait a few min after stopping the app to run the command.
Please note that if you have zombie processes left over (app processes that are owned by 1), this command will still not kill them. Only a system reboot will.
If you have to restart your app often, its better to find out what is preventing your processes from terminating cleanly than to kill those leftover processes.

3 Likes

The OS is Linux, as stated in post #5.
Linux distros have got pgrep/pkill soon after Sun introduced them on Solaris. They were pretty welcome because the traditional Linux commands pidof/killall got distro-specific options.
Also HP-UX 11.31 got pgrep/pkill. (When will AIX tune in?)

Regarding kill, I second RudiC that you must consult the shell's man page to ensure that its kill builtin supports -1

And yes, a kill -9 is a last resort, if the only alternative is a system reboot. It might leave shared memory, semaphores, temporary files, etc. behind.

Good afternoon

I used the command to kill 3004 prcesseses but it kill somme processees my own session bu processes realted to a shell called CHECK_PORT_PROCESS_MAIN.sh could get killed

pkill -u perm_adm && sleep 5 && pkill -9 -u perm_adm
root@proermpaymweb02 app]# ps -ef | grep CHECK_PORT_PROCESS_MAIN.sh | wc -l

3004

[root@proermpaymweb02 app]# ps -ef | grep CHECK_PORT_PROCESS_MAIN.sh | head -100

perm_ad+   308  8009  0 05:53 ?        00:00:00 /bin/bash /app/perm/backend/check_port_process/CHECK_PORT_PROCESS_MAIN.sh

perm_ad+   313  8009  0 03:31 ?        00:00:00 /bin/bash /app/perm/backend/check_port_process/CHECK_PORT_PROCESS_MAIN.sh

perm_ad+   326  8009  0 05:53 ?        00:00:00 /bin/bash /app/perm/backend/check_port_process/CHECK_PORT_PROCESS_MAIN.sh

perm_ad+   340  8009  0 03:31 ?        00:00:00 /bin/bash /app/perm/backend/check_port_process/CHECK_PORT_PROCESS_MAIN.sh

perm_ad+   341  8009  0 05:53 ?        00:00:00 /bin/bash /app/perm/backend/check_port_process/CHECK_PORT_PROCESS_MAIN.sh

perm_ad+   359  8009  0 03:32 ?        00:00:00 /bin/bash /app/perm/backend/check_port_process/CHECK_PORT_PROCESS_MAIN.sh

perm_ad+   375  8009  0 05:53 ?        00:00:00 /bin/bash /app/perm/backend/check_port_process/CHECK_PORT_PROCESS_MAIN.sh

[/CODE]

This shell runs every 5 minutes but lastly it gets stuck and fills up the server the server with a huge amount of processes most of them with CHECK_PORT_PROCESS script

So The system Administrator can not kill these processes and He/she had to Restart the server many times

I appreciate your help in advanced

Looks like a broken /app/perm/backend/check_port_process/CHECK_PORT_PROCESS_MAIN.sh script.
Can you post content of that script perhaps ?

Script hangs due to some condition, one should debug it.

Hope that helps
Regards
Peasant.

Give the process name! The short name is bash but with -f it takes the full name or a part of it.

pkill -u perm_adm -f CHECK_PORT_PROCESS_MAIN.sh && sleep 5 && pkill -9 -u perm_adm -f CHECK_PORT_PROCESS_MAIN.sh