Mac OS X El Capitan 10.11.2, Cassandra 2.2.3, kill pid not working - macos

Using Mac OS X El Capitan 10.11.2 and started Cassandra ( version 2.2.3) in the terminal by giving "cassandra -f" command.
Cassandra started good and able to connect using cqlsh.
Then quitted cqlsh, so its no more connecting to cassandra # port 9042
I m now trying to kill the running cassandra by doing the below:
ps -ef | grep cassandra
sudo kill -9 PID
But it does not kill the process, still cassandra is running. Not sure how to stop it now.

Just type:
ps aux | grep cassandra
Find the PID (it's always the 5 digits and if it have more than one, choose the lower) and then
kill <PID>
:)

The command ps -ef | grep cassandra should be returning two PIDs, one for cassandra and another for your grep command which also contains the word cassandra. There's a good chance that you're trying to kill the grep command, which has already died. So, make sure that you're killing the correct process.
Also, if all else fails, you can restart.

Related

Constantly having to kill worker processes to start up my Phoenix app

I am currently working on a Phoenix backend with React-Redux frontend application. My task is to develop a new component, but I am starting to get annoyed with having to run this all the time:
$ lsof -i tcp:3000
$ kill -9 PID
because if not it tells me Something is already running on port 3000.
I get this message in terminal even when its just the Chrome browser with docs in the background. I don't want to have to shut down my browser worker processes just to start this app and I have never seen this behavior before.
Where could the problem lie? Keep in mind I did not build this application, and that I am fairly new to the Phoenix framework.
At any given time when I did an lsof -i tcp:3000 these are the processes running:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 13691 username 24u IPv4 0x19aa008389bcc55 0t0 TCP *:hbci (LISTEN)
So in dev.exs it shows port: 4000 but thats the Phoenix backend, there is also a React-Redux frontend running on port 3000 so I don't believe changing the port on the Phoenix backend would help in this case.
I found a temporary solution by running this script before starting up Phoenix:
lsof -i :3000 | awk '$1 == "node" { print $2 }' | uniq | xargs kill -9
lsof - list open files
| awk '$1 == "node" { print $2 } - dollar sign indicates column 1 equals node, if it is grab the PID, unique-ing it so it can kill property and pass the PID and kill it.

how to stop http-server on a specific port?

I am using http-server in order to load http://localhost:8484 on a specific folder. (For testing purposes)
the os commands I run in my code are:
http-server -p 8484 test/
and after I finish downloading whatever I run:
http-server stop
However, after the test is done, I see that the http-server with port 8484 is still alive!
by running ps aux | grep http
What command should I run in order to stop it?
I am using Mac OSX (El Capitan version)
I write the code in erlang (though I don't think it matters since I am running shell commands from the code).
http-server: https://www.npmjs.com/package/http-server
My code in erlang:
my_test_() ->
Pid = spawn(fun() ->
Info = os:cmd("http-server -p 8484 test/resources"),
io:format(user,"*** Server: ~p~n",[Info])
end),
%%% Do some job %%%
Pid2 = spawn(fun() ->
Info = os:cmd("http-server stop"),
timer:sleep(200),
io:format(user,"*** Server stop: ~p~n",[Info])
end),
timer:sleep(200),
exit(Pid2, kill),
exit(Pid, kill).
Use:
kill -9 {pid}
Also, out of interest, if you want to see all processes running on a specific port, use:
lsof -i :{port}
EDIT: Using kill -9... is a bit harsh, I know, there is probably a more graceful way of doing it, but it does get the job done ;-)
For Windows users use the command prompt (cmd):
Method 1:
Just do Control+c on the same console where the http-server is running
Method 2: Find and Kill the process:
i. Find the process-id which uses the particular port number (say 8484)
netstat -ano | findstr 8484
Result: TCP 0.0.0.0:8484 0.0.0.0:0 LISTENING 21816
ii. Kill the process using the found process-id (say 21816)
taskkill /F /PID 21816
You can use perc - since Node.js http-server is not Erlang process, but Unix process, you need to use the module (or dig it's code to see the implementation ;) ) .
Alternatively, from Erlang os:cmd("kill -9 5607"). (where 5607 is your unix pid);

Is there a Terminal command that I can use to shut down a mongod process in OS X?

mongod --shutdown is not available on OS X. The only good way seems to be using the mongo interface. Can I shut down a mongod process that was started in the background using the --fork flag using the command line? Any way to use kill with ps?
I'm trying to shut down MongoDB using an npm posttest script (just a command that's run after my unit tests).
Either find out the pid using ps | grep mongod or echo $! after starting it up (the variable $! holds the pid of the last started process) and use kill pid.
Or, simply use mongo admin --eval "db.shutdownServer()", which throws an error but seems to work anyway. You can always pipe undesired output to /dev/null.

Unable to stop Webrick launched by "rackup"

I'm developing a Sinatra application and I'm using "rackup" to start Webrick. What should I do to stop it? Now I'm using Ctrl+Z and it seems like it stops. However when I try to start it again it will say that the port is already bound.
I tried it with many ports and each time it started, stopped and then said it was in use when I restarted it again.
How do I solve it?
Ctrl+Z will just "pause" the process, not terminate / kill it.
To truly kill it, find it in the process table and do kill -9 [PID]
like:
ps auxwww | grep ruby
slivu 16244 0.0 0.5 2551140 61220 s020 R+ 1:18AM 0:10.70 ruby app.rb
the second column(16244) is the PID.
The other way is to "catch" the INT signal with Ruby and exit the app explicitly.
in your app:
Signal.trap 'INT' do
Process.kill 9, Process.pid
end
Extending on slivu's reply,
use CTRL+C to kill the process if you are still in the same terminal.
If you are launching it in the background, or want to kill from a different terminal, use
ps aux | grep [r]ackup | awk '{print $2}' | xargs sudo kill -9

Mac OS X terminal killall won't kill running process

I have an instance of lighttpd running. When I do "ps -axc" the process is listed as
"614 ?? 0:00.15 lighttpd"
But when I do "killall lighttpd" I get
No matching processes belonging to you were found
I'm on Mac OS X 10.5.6. Is there something I'm missing?
As per the other response, if it's not your process, prepend sudo if you're an administrator. If not, you may be out of luck.
Also, try sudo killall -9 lighttpd which sends the specific signal KILL instead of TERM.
Just to be sure you can also try sudo kill -9 614 using the PID.
Is the task written in the ps aux list in brackets? If so, it is a zombie, it is waiting some I/O task, which probably never completes. You can't kill it as far as I know.
Does it belong to you ? If you do
ps aux | grep lighttpd
that will give you the user id associated with that process (I'm guessing it's chowned to another user)
It works: killall -u root -c lighttpd
Try
sudo kill -9 `pgrep lighttpd`

Resources