I'm working with Amazon's DynamoDB and I can't figure out how to programmatically kill the process reliably by name or PID.

I need to restart it since I'm holding all data in memory and I can delete the entire thing by just easily restarting the process. Problem is I can't figure out how to kill it as easily as starting it.

ps -ax | grep "Dynamo" returns 19355 ttys001 0:28.31 /usr/bin/java -Djava.library.path=./DynamoDBLocal_lib -jar /Users/user/workspace/lib/DynamoDBLocal.jar -sharedDb -port 8000 -inMemory

But when I try killall DynamoDBLocal.jar I receive No matching processes belonging to you were found and the PID changes every time it's started up.

How can I programmatically find the PID to send to kill -9 PID or properly killall by name?

EDIT: Finished! Here's my work to share with others:

alias start_dynamo='java -Djava.library.path=./DynamoDBLocal_lib -jar /Users/user/workspace/lib/DynamoDBLocal.jar -sharedDb -port 8000 -inMemory &'

alias end_dynamo="kill `ps -ax | grep Dynamo | grep -v grep | awk '{print $1}'`"

alias restart_dynamo='end_dynamo; start_dynamo'

1 Answer 1

kill `ps -ax |grep Dynamo |awk '{print $1}'` 

should do it. note, this will kill any proc that matches Dynamo

  • this works great but do you know how to convert it into an alias? the escaping of special characters is not trivial unfortunately. Mar 22, 2017 at 21:26
  • I've successfully adopted your command @skarface. Added grep -v grep to ignore the grep command and attempted to escape the command correctly to use in an alias. I get some lengthy bash noise but it's not the end of the world. Would like to remove it if possible but I'm accepting your answer regardless since it worked. Mar 22, 2017 at 21:37
  • 1
    Try wrapping the {print $1} in single quotes rather than double quotes to avoid shell interpolation of the $1
    – skarface
    Mar 23, 2017 at 16:18
  • hey that worked! thanks skarface!! i swapped my single quotes in the alias for double quotes and used single quotes around '{print $1}'. i've edited my answer with the updated aliases. thanks again. Mar 23, 2017 at 17:47
  • 1
    quoting for the shell has always been .... enjoyable :)
    – skarface
    Mar 23, 2017 at 20:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .