I have server running with nohup on port 80. I try
ps aux | grep nohup
and get
root 9234 0.0 0.1 11740 932 pts/1 S+ 15:19 0:00 grep --color=auto nohup
I then try kill -9 11740 (which I believe is the PID) and get an error stating 'no such process." I can't figure out how else to remove this. Any help is appreciated. Thanks
11740 is virtual memory size. PID is the second field, 9234.
The process in your output is grep command itself, not nohup.
You won't see standalone nohup process. When you start some process with nohup my_executable, nohup closes/redirects stdin/stdout/stderr properly, setups necessary signal handlers and replaces itself with my_executable. Search instead for executable which was started with nohup, e.g. ps aux | grep my_executable | grep -v grep
The process you are seeing is the process from your grep command. So by the time you are trying to kill it, the process is already over.
To keep it out of the output use:
ps aux | grep nohup | grep -v 'grep'
It looks like you don't have a nohup process running
Related
I have to do the same thing many times a day:
ps aux
look for process running ssh to one of my servers ...
kill -9 <pid>
I'm looking to see if I can alias process into one line. The output of ps aux is usually something like this:
user 6871 0.0 0.0 4351260 8 ?? Ss 3:28PM 0:05.95 ssh -Nf -L 18881:my-server:18881
user 3018 0.0 0.0 4334292 52 ?? S 12:08PM 0:00.15 /usr/bin/ssh-agent -l
user 9687 0.0 0.0 4294392 928 s002 S+ 10:48AM 0:00.00 grep ssh
I always want to kill the process with the my-server in it.
Does anyone know how I could accomplish this?
for pid in $(ps aux | grep "[m]y-server" | awk '{print $2}'); do kill -9 $pid; done
ps aux | grep "[m]y-server" | awk '{print $2}' - this part gives you list of pids processes that include "my-server". And this script will go through this list and kill all this processes.
I use pgrep -- if you're sure you want to kill all the processes that match:
$ kill -9 `pgrep my-server`
A simple solution is to use pkill:
sudo pkill my-server
I am trying to kill a process in linux
ps -aux
root 14074 0.0 0.4 6586120 67452 pts/0 Sl 22:45 0:01 java -cp target/cronscheduler-1.0-SNAPSHOT.jar com.cronscheduler.QuartzMain
Kill the process in the stop script using the below command
ps aux | grep "java -cp target/cronscheduler-1.0-SNAPSHOT.jar com.cronscheduler.QuartzMain" | \
grep -v grep | awk '{print $2}' | xargs kill -9
Issue is this command works fine when cronscheduler.QuartzMain is running. But when this process is already killed then the above command throws error
Usage:
kill [options] <pid|name> [...]
Your inputs on removing the errors are appreciated
pkill can search through the complete command line. Try
pkill -9 -f 'java -cp target/cronscheduler-1.0-SNAPSHOT.jar com.cronscheduler.QuartzMain'
Your command may create errors, because it sends more than the pid (the complete line from ps) to kill.
One of the solution I found was to redirect the error message :
cat /etc/*.conf 2> /dev/null
ps aux | grep httpd
httpd 3486 0.0 0.1 4248 1432 ? S Jul31 0:00 /usr/sbin/httpd -f /etc/httpd/httpd.conf
# kill 3486
OR
$ sudo kill 3486
Please try below this will help in clearing the child process id's as well.
for i in `ps -ef| grep "java -cp target/cronscheduler-1.0-SNAPSHOT.jar com.cronscheduler.QuartzMain" | grep -v grep | awk '{print $2}'`
do
ptree $i|awk '{print $1}' >>pids.txt
done
for i in $(cat pids.txt)
do
kill -9 $i
done
I'm trying to execute the following command:
ps aux | grep com.scheduler.app.workermain | kill -15 [pid]
How can I obtain the [pid] (or list of PID) using ps aux | grep "expression" and pipe that to kill? There may be zero or many processes running the machine. This is part of an automated job, to ensure all the processes spun will be terminated.
A sample line from the command line, when ps aux | grep com.scheduler.app.workermain is executed is:
jenkins 12373 1.1 4.2 2905440 173628 ? Sl 19:28 0:05 java -Xmx600m -Dlog4j.configurationFile=log4j2-trace.xml -Dpid=foobar -Dipaddr=127.0.0.1 -cp build/classes:build/dependency/* com.scheduler.app.workermain testing.properties
pkill is used for exactly this purpose. How about:
pkill -15 -f com.scheduler.app.workermain
Also if you just want to grep for a PID you can use pgrep:
pgrep -f com.scheduler.app.workermain
pkill man page
kill -15 $(ps aux | grep -i com.scheduler.app.workermain | awk -F' ' '{ print $2 }')
One of possible solutions is to use the pidof command:
kill $( pidof com.scheduler.app.workermain )
PS. You don't need to pass -15 (or -TERM) to the kill command, as SIGTERM is the default signal sent.
I am trying to stop kibana on SSH with kill but it respawns immediatly
dagatsoin#dagatsoin.io [~/logstash]# ps aux | grep kibana
533 28778 0.0 0.0 9292 876 pts/2 S+ 00:16 0:00 grep kibana
dagatsoin#dagatsoin.io [~/logstash]# kill -kill 28778
-bash: kill: (28778) - Aucun processus de ce type
dagatsoin#dagatsoin.io [~/logstash]# ps aux | grep kibana
533 28780 0.0 0.0 9292 876 pts/2 S+ 00:16 0:00 grep kibana
dagatsoin#dagatsoin.io [~/logstash]#
How do you kill this process ?
As mentioned the output that you are seeing is from the ps aux | grep kibana command that you ran. I'm guessing you started kibana using by running the kibana scipt in the bin directory. In this case do something like this:
ps -ef | grep '.*node/bin/node.*src/cli'
Look for the line that looks something like this:
username 5989 2989 1 11:33 pts/1 00:00:05 ./../node/bin/node ./../src/cli
Then run a kill -9 5989 If you have multiple output rows make sure you kill the correct process.
You try to kill your grep process, not kibana service who is not running currently.
For me, nothing worked on Ubuntu 18, except this:
systemctl stop snap.kibana.kibana
You kibana process is not running. when you do run a ps aux command and pipe it with a grep command, grep will be running as a separate process. hence its shows up in the ps aux output as process no 28778 or 28780. you can observe that the process number is changing. every-time you stop the ps aux grep process also ends as it is piped with ps and it starts as a new process(id) when you rerun it. hence you are getting an error when you run kill -kill 28778 as it has already stopped.
When you start your Kibana using the start script in $KIBANA_HOME/bin/kibana, this script runs another script in $KIBANA_HOME/node/bin/node. Remember, you must search using ps command for a different name (not Kibana name).
So I use ps awwwx | grep -i ./bin/../node/bin/node | grep -v grep on new Linux versions like Ubuntu 18 (or ps -ef | grep -i ./bin/../node/bin/node | grep -v grep on older versions) to search for the Kibana node. This command will give you the accurate PID and you can kill the Kibana node via mentioned PID.
grep -v grep part of this command is just to omit the unnecessary lines from the output of the command.
I want linux script to kill java program running on console.
Following is the process running as jar.
[rapp#s1-dlap0 ~]$ ps -ef |grep java
rapp 9473 1 0 15:03 pts/1 00:00:15 java -jar wskInterface-0.0.1-SNAPSHOT-jar-with-dependencies.jar
rapp 10177 8995 0 16:00 pts/1 00:00:00 grep java
[rapp#s1-dlap0 ~]$
You can simply use pkill -f like this:
pkill -f 'java -jar'
EDIT: To kill a particular java process running your specific jar use this regex based pkill command:
pkill -f 'java.*lnwskInterface'
If you just want to kill any/all java processes, then all you need is;
killall java
If, however, you want to kill the wskInterface process in particular, then you're most of the way there, you just need to strip out the process id;
PID=`ps -ef | grep wskInterface | awk '{ print $2 }'`
kill -9 $PID
Should do it, there is probably an easier way though...
if there are multiple java processes and you wish to kill them with one command
try the below command
kill -9 $(ps -ef | pgrep -f "java")
replace "java" with any process string identifier , to kill anything else.
pkill -f for whatever reason does not work for me. Whatever that does, it seems very finicky about actually grepping through what ps aux shows me clearly is there.
After an afternoon of swearing I went for putting the following in my start script:
(ps aux | grep -v -e 'grep ' | grep MainApp | tr -s " " | cut -d " " -f 2 | xargs kill -9 ) || true
Use jps to list running java processes. The command returns the process id along with the main class. You can use kill command to kill the process with the returned id or use following one liner script.
kill $(jps | grep <MainClass> | awk '{print $1}')
MainClass is a class in your running java program which contains the main method.