how to Kill hadoop task started using hadoop jar command? - hadoop

I'm pretty new to using Hadoop.
I used hadoop jar command like the one below -
hadoop jar $jarpath/BDAnalytics.jar \
bigdat.twitter.crawler.CrawlTwitter \
$crwlInputFile > $logsFldr/crawler_$1.log 2>&1 &
But I need to kill this process, and not able to understand how.
There are a lot of links to kill hadoop jobs but since this is not a job but a task/java process.
I will high appreciate if you could let me know the command to kill such a process.
Thanks in advance!
-RG

You can use the shell command kill. For example, use ps -ef | grep bigdat.twitter.crawler.CrawlTwitter to find the pid, and use kill -9 pid_of_the_process to kill it. You can write a script containing the following command to do the kill action:
#!/bin/bash
kill -9 $(ps -ef | grep bigdat.twitter.crawler.CrawlTwitter | sed "s/\s\+/\t/g" | cut -f2)

Related

How do I make a stop after a run?

If I do a:
npm run script
Can I stop it with a stop?
npm stop script
Why I tried it and it does not work.
I know that with the combination of "Ctrl + c" I kill it, but I want to do it by command.
Try something like that:
ps -ef | grep script | awk '{print $2}' | head -n1 | xargs kill -9
This command should find first process named script on the list of all unix processes created by all users and kill it by with using its PID.

How to kill a process with 'kill' combined with 'grep'

I'd like to kill a process/script with a simple command using. At the moment I do the following
ps -ef | grep myscriptname
kill 123456
But is there a way to maybe combine the 2 command together so I don't need to look and manually write the pid, something like this kill grep myscriptname?
You want pkill:
pkill myscriptname
On some systems there is a similar tool called killall, but be careful because on Solaris it really does kill everything!
Note that there is also pgrep which you can use to replace your ps | grep pipeline:
pgrep myscriptname
It prints the PID for you, and nothing else.
Another alternative is using the pidof command:
kill $(pidof processname)
you can try this simple trick
pkill -f "my_sript_filename"
I use kill $(pgrep <program name>), it works.
Another alternative, pgrep with xargs
ps aux | pgrep gitlab | xargs kill
An alternative is piping to the xargs command:
ps -ef | grep myscriptname | xargs kill
http://man7.org/linux/man-pages/man1/xargs.1.html

Stop background jobs after exiting the shell

I use nohup to start several background jobs. Then I can use job -l to display those jobs and use fg jobID to put them front and stop them. But now I have quitted the session and after I login again and use "job -l" to display jobs, as expected, it displays nothing. Now, I want to know now could I stop those background jobs? Is there anyway similar to use fg jobpid to put it front and kill it? Thanks in advance!
Try this (be careful, it can be dangerous):
ps -ef | grep 'some string int the process command' | grep -v grep | awk '{print $2}' | xargs kill -9
You can also use something like tmux or screen and detach from the shell, when you log back in re-attach to the shell and run your normal commands as if you'd been logged in the whole time.

Jenkins job to kill process (Tomcat) over ssh

I am using a Jenkins job to run a few simple shell commands (over ssh, via the Jenkins SSH Plugin); the commands are supposed to shut down a running Tomcat server:
sudo /opt/tomcat/bin/catalina.sh stop
ps xu | awk '/[t]omcat/{print $2}' | xargs -r kill -9
The job executes fine and does terminate the Tomcat, but unfortunately it also fails; the full output is:
[SSH] executing pre build script:
sudo /opt/tomcat/bin/catalina.sh stop
ps xu | awk '/[t]omcat/{print $2}' | xargs kill -9
[SSH] exit-status: -1
Finished: FAILURE
Any idea why the exit code of the command if -1? I have tried several variations without any luck.
Thanks.
You should examine the output of ps xu. Since kill will kill the processes sequentially, it may be the case that if there are multiple tomcat processes yielded by ps xu, the other ones will automatically terminate after the first one is terminated. Then kill attempts to terminate processes that no longer exist.
I suspect that Jenkins doesn't like the no process killed that the kill command prints of it doesn't run. Try redirecting stdout to /dev/null.
The questions is a bit old but as I stumbled upon that, here's another suggestion.
ps xu | awk '/[t]omcat/{print $2}'
returns the running tomcat AND the awk process itself, see here
<user> 2370 0.0 0.0 26144 1440 pts/7 R+ 10:51 0:00 awk /[t]omcat/{print $2}
The awk process instantly ends itself before running xargs on it, so one of the xargs has an exit code unequal 0.
Try running killall tomcat
Can you just do pkill tomcat?

Killing processes SHELL

This command ps -ef | grep php returns a list of processes
I want to kill in one command or with a shell script all those processes
Thanks
The easiest way to kill all commands with a given name is to use killall:
killall php
Note, this only sends an interrupt signal. This should be enough if the processes are behaving. If they're not dying from that, you can forcibly kill them using
killall -9 php
The normal way to do this is to use xargs as in ps -ef | grep php | xargs kill, but there are several ways to do this.
ps -ef lists all processes and then you use grep to pick a few lines that mention "php". This means that also commands that have "php" as part of their command line will match, and be killed. If you really want to match the command (and not the arguments as well), it is probably better to use pgrep php.
You can use a shell backtick to provide the output of a command as arguments to another command, as in
kill `pgrep php`
If you want to kill processes only, there is a command pkill that matches a pattern to the command. This can not be used if you want to do something else with the processes though. This means that if you want to kill all processes where the command contain "php", you can do this using pkill php.
Hope this helps.
You can find its pid (it's on the first column ps prints) and use the kill command to forcibly kill it:
kill -9 <pid you found>
Use xargs:
ps -ef | grep php | grep -v grep | awk '{print $2}' | xargs kill -9
grep -v grep is exclude the command itself and awk gives the list of PIDs which are then passed kill command.
Use pkill php. More on this topic in this similar question: How can I kill a process by name instead of PID?

Resources