How to kill a particular process in Linux? [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I would like to kill a particular process (it is a program which name is test.exe) in Linux. To do that I can type:
ps aux | grep test.exe
And then:
kill -9 process_id_of_test_exe
As You can see I need to type commands several times (not immediately). The question is how to do that in one command. Take the process_id of test.exe and give to kill. I think that I need to write a script in such case. Thanks.

Use this command to get PID
pidof test.exe
1044
Then to kill it:
kill 1044
And then join them:
kill $(pidof test.exe)
You can also use your command:
kill -9 $(ps aux | grep [t]est.exe)
The [t] prevents grep from grepping itself.

Try:
killall test.exe
See man killall for more details!

You can combine kill -9 with pgrep like follows:
kill -9 `pgrep test.exe`

For killing all processess with keyword test.exe, try
pkill -9 -f test.exe

Related

How to set the output of ^Z (Control-Z) to output the PID of the stopped process? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 months ago.
Improve this question
I start my script bash test.sh and then press Control-Z and get this:
^Z
[1]+ Stopped bash test.sh
All fine. But I want that the output also has the PID.
I know I can do this ps $(jobs -p) afterwards to get the PID. But how it is possible that the output of Control-Z prints directly the PID?
I don't think that's possible. That said, perhaps you can take a step back and clarify why you are hoping to do that?
Because what you can do is directly refer to the particular job with %1 (or %<n> more generally, if you have multiple background jobs) for several built-in commands (fg, bg, kill, ...):
$ sleep 30
^Z
[1]+ Stopped sleep 30
$ kill %1
[1]+ Terminated: 15 sleep 30
More details in man bash or here: https://www.gnu.org/software/bash/manual/bash.html#Job-Control-Basics

How to kill a running script from another script? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
I have a a.sh script that executes a infinite loop with a list of commands in background in a Debian machine and I would like to use another script b.sh to end with a.sh. As far as I know pkill -f a.sh is one way of doing it, but I want to know if there is another way of doing it
man -k kill shows many commands to kill processes. Watch out (1) (general commands) and (8) (admin commands). At my system I get (manually filtered):
killproc (8) - Send signals to processes by full path name
docker-container-kill (1) - Kill one or more running containers
docker-kill (1) - Kill one or more running containers
kill (1) - terminate a process
killall (1) - kill processes by name
killall5 (8) - send a signal to all processes.
pkill (1) - look up or signal processes based on name and other attributes
skill (1) - send a signal or report process status
If you run a.sh from b.sh you can get the process id of a.sh
b.sh
a.sh & # Execute a.sh in the background
APID=$! # $APID is now the pid of a.sh
#do some stuff or wait
kill -SIGTERM $APID # Give the process a chance to shut down
kill -SIGKILL $APID # Certain kill
This way you can kill the particular instance of a.sh if you have multiple concurrent
instances.

How to kill certain process running more than 36 hours and containing certain phrasse in its command? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
on the Linux (CentOS 6), i want to kill process containing "pkgacc" in its command (so no exact command but just partial match) if it is running more than 36 hours.
There is related question: How do you kill all Linux processes that are older than a certain age? but any of the solutions provided do not work for me.
when executing:
if [[ "$(uname)" = "Linux" ]];then killall --older-than 1h someprocessname;fi
It just return killall usage page on how to use killall, in its manual page there is no mention about "--older-than" switch.
It is infinitely easier to invoke a program in a wrapper like timeout from GNU coreutils than to go hunting for them after the fact. In particular because timeout owns its process, there is no ambiguity that it kills the right process. Thus
timeout 36h pkgaccess --pkg_option --another_option package_name
where I made up the names and options for the pkgaccess command since you didn't give them. This process will run no longer than 36 hours.
I think you could do something like
ps -eo pid,cmd,etime
then you could parse the output with grep searching for you process,
something like that:
ps -eo pid,cmd,etime | grep pkgacc
you will have some output with one or more result, the last column from the output must be the time of running process, so one more little bash effort
and you could check if the time is greater than 36 hours.
#!/bin/bash
FOO=$(ps -eo pid,cmd,etime | grep -m 1 pkgacc | awk '{ print $1" "$3 }'| sed -e 's/\://g')
IFS=' ' read -r -a array <<< "$FOO"
if [ "${array[1]}" -gt "360000" ]; then
echo "kill the process: ${array[0]}"
else
echo "process was not found or time less than 36 hours"
fi
I think that could solve part of your problem,
see that I do not explicit kill the process but just indicate
what it is. You could improve the idea from that.

The process appear again automatically after I killed it [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I try to kill a process with sudo kill 30602. But after I killed it I use ps aux | grep gmond to check, it appear again with another pid.That's like:
ganglia 30997 0.0 0.1 121812 2128 ? Ssl 16:05 0:00 /usr/sbin/gmond --pid-file=/var/run/ganglia-monitor.pid
Whatever how I kill it, it just appear again with another pid, even with kill -9.
What's the problem? And how to solve this?
You should change the entry in the /etc/inittab file. Probably your gmond service entry is starting with respawn. It will respawn every time you kill the process.
Link: To disable the process you have to edit /etc/inittab and comment out that line. To inform init about this change you have to send a SIGHUP to init:
kill -HUP pid-of-init
The /etc/inittab file was the configuration file used by the original System V init daemon. The Upstart init daemon does not use this file, and instead reads its configuration from files in /etc/init directory.

How to kill more than one process in linux? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I want to kill some of Apache server process in Linux.
Please help me in this.
if you have pid of the processes that want to kill then use kill command.
kill pid1 [pid2 pid3 ...]
And if this doesn't kill the processes you can add -9 flag to kill command to forcefully kill the processes like
kill -9 pid1 [pid2 pid3 ...]
To get the pid of the process you can use ps command as
ps ax | grep apache
first column of output is the pid of the process.
Try the following:
killall apache2
if you want to kill all apache processes.
ps aux | grep apache2
will show the apache servers with their PID. Then you can kill selectively:
kill -9 pid1 pid5
Note the Linux command killall. You can kill processes by name and thus do something a little more coarse-grained than using the pid. You can use names or regular expressions (with the -r option) to specifiy your victims.
Use a normal SIGTERM (default) to begin with. This will let the processes catch the signal, and if they're well-behaved they'll clear up/close resources properly and then exit. Only if the processes don't respond should you use the SIGKILL (-9) signal.

Resources