Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
653
votes
16
answers
820989
views
What if 'kill -9' does not work?
I have a process I can't kill with `kill -9 `. What's the problem in such a case, especially since I am the owner of that process. I thought nothing could evade that `kill` option.
I have a process I can't kill with
kill -9
. What's the problem in such a case, especially since I am the owner of that process. I thought nothing could evade that kill
option.
tshepang
(67482 rep)
Jan 10, 2011, 07:51 PM
• Last activity: Jul 28, 2025, 03:20 PM
-1
votes
0
answers
47
views
Killing errant kernel processes - good idea or not?
99% of the time, `sudo kill -9` on a user space process will result in a (relatively) successful termination. However, what extra considerations might there be for killing kernel tasks? A sample scenario might be field testing a new device driver where I also have a watchdog process that monitors th...
99% of the time,
sudo kill -9
on a user space process will result in a (relatively) successful termination. However, what extra considerations might there be for killing kernel tasks?
A sample scenario might be field testing a new device driver where I also have a watchdog process that monitors the driver. If my watchdog detects the driver status API returning a fatal error condition, the driver not responding within a few seconds, excessive CPU usage, corruption of the code segment, etc, how safe is it to just kill and restart the process kernel module, ignoring issues like leaving the device it is driving in an intermediate state?
If lsmod
shows it is being used by other modules, are there other issues to consider?
[This is a related question](https://unix.stackexchange.com/q/152090/46316) as I envisage my driver starting on init
.
Ken Y-N
(251 rep)
Jul 25, 2025, 01:45 AM
• Last activity: Jul 25, 2025, 06:50 AM
9
votes
2
answers
3290
views
Linux kernel bug - How do you kill a process that won't die?
How do I kill a process that cannot be killed? ```none user@kubuntu22:~$ ps -ef |grep smbd nobody 3532354 1 0 16:30 ? 00:00:00 /usr/sbin/smbd --foreground --no-process-group user@kubuntu22:~$ sudo killall smbd user@kubuntu22:~$ ps -ef |grep smbd nobody 3532354 1 0 16:30 ? 00:00:00 /usr/sbin/smbd --f...
How do I kill a process that cannot be killed?
user@kubuntu22:~$ ps -ef |grep smbd
nobody 3532354 1 0 16:30 ? 00:00:00 /usr/sbin/smbd --foreground --no-process-group
user@kubuntu22:~$ sudo killall smbd
user@kubuntu22:~$ ps -ef |grep smbd
nobody 3532354 1 0 16:30 ? 00:00:00 /usr/sbin/smbd --foreground --no-process-group
user@kubuntu22:~$ sudo killall -KILL smbd
user@kubuntu22:~$ ps -ef |grep smbd
nobody 3532354 1 0 16:30 ? 00:00:00 /usr/sbin/smbd --foreground --no-process-group
user@kubuntu22:~$ sudo kill -9 3532354
user@kubuntu22:~$ ps -ef |grep smbd
nobody 3532354 1 0 16:30 ? 00:00:00 /usr/sbin/smbd --foreground --no-process-group
System information:
(Ubuntu 22.04.5 LTS jammy Linux 6.5.0-35-generic x86_64)
Edit:
user@kubuntu22:~$ ps ax |grep smbd
3532354 ? D 0:00 /usr/sbin/smbd --foreground --no-process-group
I guess it's stuck in the "erroneous uninterruptible sleep " state (D
)
And it has the network port open so running another smbd
works but I can't connect.
@kubuntu22:~$ sudo netstat -tunap |grep smbd
tcp 0 0 0.0.0.0:139 0.0.0.0:* LISTEN 3564116/smbd
tcp 0 0 0.0.0.0:445 0.0.0.0:* LISTEN 3564116/smbd
tcp 1117 0 127.0.0.1:445 127.0.0.1:41882 CLOSE_WAIT 3532354/smbd
tcp6 0 0 :::139 :::* LISTEN 3564116/smbd
tcp6 0 0 :::445 :::* LISTEN 3564116/smbd
codywohlers
(177 rep)
Jul 14, 2025, 10:43 PM
• Last activity: Jul 18, 2025, 01:26 AM
42
votes
6
answers
11887
views
Does pressing ctrl-c several times make the running program close more quickly?
I often start to read a huge file and then want to quit after a while, but there is a lag from pressing Ctrl + C to the program stops. Is there a chance of shortening the lag by pressing the Ctrl + C key several times? Or am I wasting my keypresses?
I often start to read a huge file and then want to quit after a while, but there is a lag from pressing
Ctrl+C to the program stops. Is there a chance of shortening the lag by pressing the Ctrl+C key several times? Or am I wasting my keypresses?
Ctrl+C to the program stops. Is there a chance of shortening the lag by pressing the Ctrl+C key several times? Or am I wasting my keypresses?
The Unfun Cat
(3451 rep)
Jan 15, 2014, 07:33 AM
• Last activity: Jul 8, 2025, 10:00 AM
0
votes
1
answers
97
views
How to send SIGQUIT or SIGINT using bash shell to a shell script
According to [BASH manual][1] page, > When Bash receives a SIGINT, it breaks out of any executing loops. In > all cases, Bash ignores SIGQUIT. So if there was a shell script, started from bash shell, to which a SIGINT or SIGQUIT is sent via the following commands, they have no effect on the script....
According to BASH manual page,
> When Bash receives a SIGINT, it breaks out of any executing loops. In
> all cases, Bash ignores SIGQUIT.
So if there was a shell script, started from bash shell, to which a SIGINT or SIGQUIT is sent via the following commands, they have no effect on the script. The script still keeps on running.
$ /usr/bin/kill --verbose --signal SIGQUIT >
sending signal 3 to pid >
$ /usr/bin/kill --verbose --signal SIGINT >
sending signal 2 to pid >
So how can a SIGQUIT or SIGINT be sent from a bash interactive shell to a shell script that has been started by another bash shell?
However if application or script is started from **systemd-user** then it receives both the signals SIGQUIT and SIGINT.
SIGQUIT has the benefit of creating a core dump when the script or application exits.
KDM
(116 rep)
Jun 3, 2025, 08:10 AM
• Last activity: Jun 3, 2025, 12:31 PM
6
votes
1
answers
7363
views
Killed process blocks TCP ports
I've had this issue on several machines. Is there some way to free this blocked port? Here is an example: Let me explain. I've killed some JAVA-Process on SUSE Linux Enterprise Server 11 SP4, which had some ports open. I used the command "kill -9 " with root user. Now it is not possible to start the...
I've had this issue on several machines. Is there some way to free this blocked port? Here is an example:
Let me explain. I've killed some JAVA-Process on SUSE Linux Enterprise Server 11 SP4, which had some ports open. I used the command "kill -9 " with root user. Now it is not possible to start the process again, because the port is still blocked. The application dies when the port is still open. But the process is definitively gone!
When I have a look with command
netstat -anop | grep -E "Sta|37941"
(also with root user), I'll get the following results:
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name Timer
[...]
tcp 0 0 172.21.63.27:42034 172.21.63.28:37941 ESTABLISHED - keepalive (2861.75/0/0)
[...]
It shows no PID! Before killing the process, it showed the PID of the process. Is there any way to free such a "dead" port? We are always need to restart the operating system to get the application started again. But this is really, really critical in our high-availability systems... so what to do if we need to kill the process in the future? This issue also happened on other unix operating systems in the past.
Any help in solving this issue for the future would be highly appreciated. Thank you all very much in advance!
mstrd308
(61 rep)
Nov 10, 2017, 12:03 AM
• Last activity: May 24, 2025, 03:00 AM
0
votes
2
answers
2082
views
How to redirect Java thread dumps from "kill -3" to a custom file instead of "catalina.out"
I used to take thread dumps using: ``` kill -3 `pidof java` ``` This creates thread dumps in `catalina.out`. How can I get that output into a different file instead of `catalina.out`? Usually, the `kill` command doesn’t output to stdout or stderr, so we can't capture it by redirecting script output...
I used to take thread dumps using:
kill -3 pidof java
This creates thread dumps in catalina.out
. How can I get that output into a different file instead of catalina.out
? Usually, the kill
command doesn’t output to stdout or stderr, so we can't capture it by redirecting script output or using exec
at the beginning. Is there any way to do this?
SAGAR Nair
(317 rep)
Dec 12, 2018, 10:56 PM
• Last activity: Apr 29, 2025, 03:11 PM
59
votes
5
answers
548638
views
How do I exit or cancel a bad bash command?
I expect to get some flak for this, but I can't find the answer anywhere. It seems like it should be so obvious. Sometimes, when I type a bad command in a bash terminal, the cursor just jumps down to the next line without any error or anything. I can't tell what I did wrong. It's like I'm stuck in t...
I expect to get some flak for this, but I can't find the answer anywhere. It seems like it should be so obvious. Sometimes, when I type a bad command in a bash terminal, the cursor just jumps down to the next line without any error or anything. I can't tell what I did wrong. It's like I'm stuck in the program. Reenactment:
$ tidy
Me: "Oops! That's not what I meant to type..."
:q
Me: "That didn't work..."
:exit
:quit
exit
quit
/exit
/quit
-exit
-quit
-wtf???
I know I screwed up but how do I get back to the prompt without closing the terminal?
Big McLargeHuge
(3296 rep)
Aug 16, 2012, 05:34 PM
• Last activity: Apr 22, 2025, 09:43 PM
1
votes
1
answers
1653
views
What is the SIGUSR2 signal, and what effect does it have?
I am CentOS 7.4 on Dell servers. I'm running this command in a script: kill -SIGUSR2 `ps -ef|grep ${rule}/etc/suricata/suricata.yaml|grep -v grep|awk '{ print $2 }'` The `ps` part here grabs PID, but what does `SIGUSR2` do? I see it's "user-defined"; how does that translate into actions?
I am CentOS 7.4 on Dell servers.
I'm running this command in a script:
kill -SIGUSR2
ps -ef|grep ${rule}/etc/suricata/suricata.yaml|grep -v grep|awk '{ print $2 }'
The ps
part here grabs PID, but what does SIGUSR2
do?
I see it's "user-defined"; how does that translate into actions?
hokie1999
(11 rep)
Dec 3, 2018, 03:14 PM
• Last activity: Apr 6, 2025, 07:48 AM
7
votes
4
answers
45202
views
killing parent process doesn't kill child
I have a question. Studying processes management I observed a strange behavior, on a CentOS 7. I know that killing a parent process, the child processes are killed also. But not in the following case. I ran the command dd, just for example: [root@server2 ~]# dd if=/dev/zero of=/dev/null & [1] 1756 [...
I have a question.
Studying processes management I observed a strange behavior, on a CentOS 7.
I know that killing a parent process, the child processes are killed also. But not in the following case. I ran the command dd, just for example:
[root@server2 ~]# dd if=/dev/zero of=/dev/null &
1756
[root@server2 ~]# ps fax | grep -B2 dd
1737 pts/2 S 0:00 \_ su -
1741 pts/2 S 0:00 \_ -bash
1756 pts/2 R 1:18 \_ dd if=/dev/zero of=/dev/null
After that I tried to kill (with SIGKILL signal) the parent process, that is the bash, but this action doesn't kill the dd process:
[root@server2 ~]# kill -9 1741
Killed
[user@server2 ~]#
The shell terminates but as you can see in the top command output, the dd process is still working:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1756 root 20 0 107948 612 512 R 99.9 0.1 10:06.98 dd
Do you have any idea about it please?
intore
(399 rep)
Apr 29, 2018, 07:51 AM
• Last activity: Feb 21, 2025, 04:40 PM
29
votes
4
answers
162030
views
Kill any service running at a specific port
I am trying to write a script that kills service running at a specific port. This is my script: a=$(ps ax | grep 4990 | grep java | awk '{print $1}') kill -9 $a It's a java program. This script works sometimes, but mysteriously fails most of the time. Is there any other way to kill a service running...
I am trying to write a script that kills service running at a specific port. This is my script:
a=$(ps ax | grep 4990 | grep java | awk '{print $1}')
kill -9 $a
It's a java program. This script works sometimes, but mysteriously fails most of the time.
Is there any other way to kill a service running on a port? My port is
4990
.
Abhishek dot py
(2403 rep)
Jul 3, 2014, 05:25 AM
• Last activity: Jan 12, 2025, 07:47 PM
2
votes
2
answers
1031
views
What are these processes and why can't I kill them?
(On OS X 10.11.3) I'm having a problem starting a java process that needs to listen on port 8040. Getting a BindException. So seems like somebody else is already listening on it. A quick check confirms that: lsof -i TCP| fgrep LISTEN | grep 8040 jspawnhel 13566 alon 255u IPv6 0x2a5edc8fe0a093d7 0t0...
(On OS X 10.11.3)
I'm having a problem starting a java process that needs to listen on port 8040. Getting a BindException. So seems like somebody else is already listening on it. A quick check confirms that:
lsof -i TCP| fgrep LISTEN | grep 8040
jspawnhel 13566 alon 255u IPv6 0x2a5edc8fe0a093d7 0t0 TCP *:8040 (LISTEN)
jspawnhel 14482 alon 255u IPv6 0x2a5edc8fe0a093d7 0t0 TCP *:8040 (LISTEN)
jspawnhel 81770 alon 255u IPv6 0x2a5edc8fe0a093d7 0t0 TCP *:8040 (LISTEN)
So, I'm trying to figure out what these processes are, but I don't understand what ps is showing me:
ps ax | grep "13566\|14482\|81770"
13566 ?? U 0:00.00 313:316
14482 ?? U 0:00.00 324:327
81770 ?? U 0:00.00 301:304
what does the "??" mean? what is 313:316 in this context?
I can't kill it either, even with -9:
kill -9 13566
ps ax | grep 13566
13566 ?? U 0:00.00 313:316
Tried many times...
Any help is appreciated.
Legato
(123 rep)
Apr 4, 2016, 02:19 PM
• Last activity: Nov 22, 2024, 12:08 AM
4
votes
4
answers
26071
views
Podman can not kill containers: not running, but state improper
When I run `podman container kill -a`, I get can only kill running containers. 11d887d57069b3ee630fd6f1b13d600485c34f5020ff09fec65f4e31dd7242a5 is in state configured: container state improper can only kill running containers. 2132c0543eedbe3c4ee8680da508fea6251d38107d5e707f260eb5aa8549409d is in st...
When I run
podman container kill -a
, I get
can only kill running containers. 11d887d57069b3ee630fd6f1b13d600485c34f5020ff09fec65f4e31dd7242a5 is in state configured: container state improper
can only kill running containers. 2132c0543eedbe3c4ee8680da508fea6251d38107d5e707f260eb5aa8549409d is in state configured: container state improper
can only kill running containers. 2db317cc73ec92e434fda88653f872e4c4cf07e9f32c0c29ecc5e69515beb96d is in state exited: container state improper
can only kill running containers. 465d133dec7a568bd8a6231036e1c489b6a6f88c65154629d75ce4161fb6e3c4 is in state exited: container state improper
Subsequent runs still show the containers. How can I get rid of them?
Evan Carroll
(34663 rep)
Nov 15, 2020, 06:43 AM
• Last activity: Nov 10, 2024, 09:54 PM
3
votes
1
answers
3512
views
Kill a running shell script, and kill all process running within it
I have a shell script running in the background, which runs 5 different jobs. When I run the shell script all 5 jobs start running in order. When I kill this shell, whichever process is running, will still continue to run, even though I have killed the shell. $ bash shell.sh & echo $! this gives me...
I have a shell script running in the background, which runs 5 different jobs.
When I run the shell script all 5 jobs start running in order.
When I kill this shell, whichever process is running, will still continue to run, even though I have killed the shell.
$ bash shell.sh & echo $!
this gives me the PID of the shell, which allows me to kill it later if I wish to do so at some point.
#!/bin/bash
JOB1
JOB2
JOB3
JOB4
JOB5
How can I make the shell kill all process running within, once it has been killed?
user
(31 rep)
Feb 4, 2016, 08:14 PM
• Last activity: Oct 19, 2024, 06:22 PM
74
votes
4
answers
80369
views
What is the difference between kill , pkill and killall?
I am familiar with `kill` command , and most of the time we just use `kill -9` to kill a process forcefully, there are many other signals that can be used with `kill`. But I wonder what are the use cases of `pkill` and `killall`, if there is already a kill command. Do `pkill` and `killall` use the `...
I am familiar with
kill
command , and most of the time we just use kill -9
to kill a process forcefully, there are many other signals that can be used with kill
. But I wonder what are the use cases of pkill
and killall
, if there is already a kill command.
Do pkill
and killall
use the kill
command in their implementation? I mean they are just wrappers over kill
or they have their own implementation?
I would also like to know how pgrep
command gets the process id from the process name.
Do all these commands use the same underlying system calls? Is there any difference from a performance point of view, which one is faster?
Ijaz Ahmad
(7382 rep)
Dec 30, 2015, 03:55 PM
• Last activity: Oct 19, 2024, 06:02 AM
0
votes
1
answers
59
views
Is there an easy way to kill all other ssh session by me(user) on the server, but keep the current ssh session through command line?
For example, if I ssh to the server at multiple office computer, how can I conveniently kill those ssh at home when I ssh to the server machine?
For example, if I ssh to the server at multiple office computer, how can I conveniently kill those ssh at home when I ssh to the server machine?
Lucar
(1 rep)
Oct 18, 2024, 11:03 PM
• Last activity: Oct 19, 2024, 03:06 AM
9
votes
2
answers
13178
views
Script ends abruptly with a Terminated message
This is my bash script. All it does is to check whether a service has started and whether some processes are running as expected. It ends abruptly with a "Terminated" message. I tried debugging it with the `set -x` flag, and I still don't know what is going wrong. Stack Overflow and Google don't sho...
This is my bash script. All it does is to check whether a service has started and whether some processes are running as expected.
It ends abruptly with a "Terminated" message. I tried debugging it with the
set -x
flag, and I still don't know what is going wrong. Stack Overflow and Google don't show me any other people with a similar problem.
The script has permissions of 755. Some commands are obfuscated, for obvious reasons.
#!/bin/bash
set -x
DAEMON_BIN=/etc/init.d/init-god
DAEMON_BIN_START="${DAEMON_BIN} start"
DAEMON_BIN_STOP="${DAEMON_BIN} stop"
SOME_VARIABLE="foo"
CHEF_CONFIG_FILE_PATH="/path/to/file"
NODE_INFO_FILE="/mnt/node_info/properties"
function get_key_value (){
value=$(grep -Po "(? /dev/null
nohup pkill -f resque &> /dev/null
eval $DAEMON_BIN_START
sleep 15
PROCESS_COUNT=ps aux | awk '/[p]rocess-name/' | wc -l
NODE_NAME=get_key_value node_name
if [[ $NODE_NAME -eq $SOME_VARIABLE && $PROCESS_COUNT -eq 1 ]]; then
echo "DAEMON and scheduler are running fine." ;
else
echo "A problem with DAEMON has occured." ;
fi
EXPECTED_PROCESS_COUNT=get_key_value no_of_workers
ACTUAL_WORKER_COUNT=ps ax | grep [r]esque-[0-9]
if [[ $EXPECTED_PROCESS_COUNT -eq $ACTUAL_WORKER_COUNT ]]; then
echo "Correct Number of workers initialized." ;
else
echo "More workers exist than are permitted." ;
fi
for (( i=0; i<${EXPECTED_PROCESS_COUNT}; i++ )); do
WORKER_NAME=get_key_value worker_${i}
COUNT=ps ax | grep ${WORKER_NAME} | grep -v grep | wc -l
if [[ $COUNT -eq 1 ]]; then
#statements
echo "${WORKER_NAME} is running."
else
echo "${WORKER_NAME} may not be running or might have more than 1 copies."
fi
done
The debug output of the script is as follows:
+ DAEMON_BIN=/etc/init.d/init-god
+ DAEMON_BIN_START='/etc/init.d/init-god start'
+ DAEMON_BIN_STOP='/etc/init.d/init-god stop'
+ SOME_VARIABLE=foo
+ CHEF_CONFIG_FILE_PATH=/path/to/file
+ NODE_INFO_FILE=/mnt/node_info/properties
+ eval /etc/init.d/init-god stop
++ /etc/init.d/init-god stop
.
Stopped all watches
Stopped god
+ nohup pkill DAEMON
+ nohup pkill -f resque
Terminated
Why does this script exit with a "Terminated" message? What should I do to prevent this from happening?
theTuxRacer
(1083 rep)
Oct 9, 2013, 05:27 AM
• Last activity: Oct 12, 2024, 02:11 PM
348
votes
13
answers
1034704
views
How to terminate a background process?
I have started a wget on remote machine in background using `&`. Suddenly it stops downloading. I want to terminate its process, then re-run the command. How can I terminate it? I haven't closed its shell window. But as you know it doesn't stop using Ctrl + C and Ctrl + Z .
I have started a wget on remote machine in background using
&
. Suddenly it stops downloading. I want to terminate its process, then re-run the command. How can I terminate it?
I haven't closed its shell window. But as you know it doesn't stop using Ctrl+C and Ctrl+Z.
Mohammad Etemaddar
(13227 rep)
Dec 12, 2013, 07:11 AM
• Last activity: Oct 9, 2024, 01:07 PM
8
votes
5
answers
37287
views
How can I automatically kill the process with the highest CPU load?
Sometimes programs will lock up in the background and cause high CPU usage. Is there any way I can programmatically ascertain which process is causing the highest CPU load at the moment and kill it?
Sometimes programs will lock up in the background and cause high CPU usage. Is there any way I can programmatically ascertain which process is causing the highest CPU load at the moment and kill it?
Glutanimate
(2328 rep)
Sep 11, 2013, 12:46 AM
• Last activity: Oct 7, 2024, 06:30 AM
2
votes
1
answers
650
views
Killing a process when some other process is finished
Given `a | b`, i'd like to kill `b` when `a` is finished. `b` is an interactive process, which doesn't terminates when `a` is finished ([`fzf`][1] in my case), and the whole `a | b` is executed in a `$()` subshell. So far what i come up with was echo $({ sleep 5 & a=$!; { wait $a; kill $b; } } | { f...
Given
a | b
, i'd like to kill b
when a
is finished. b
is an interactive process, which doesn't terminates when a
is finished (fzf
in my case), and the whole a | b
is executed in a $()
subshell.
So far what i come up with was
echo $({ sleep 5 & a=$!; { wait $a; kill $b; } } | { fzf & b=$!; })
sleep
represents a
, and fzf
represents b
, the result in the example is used by echo
, but in my case, it'd be an argument for ssh
. It seems, that $b
is not the PID of fzf
, it's empty. As far as i understand, this shouldn't be the case, since i've used {}
, and not ()
, so it's not executed in a subshell.
lennoff
(121 rep)
Dec 10, 2018, 10:14 PM
• Last activity: Oct 6, 2024, 09:59 AM
Showing page 1 of 20 total questions