Kill command is not working for me in Linux - linux-kernel

I am unable to kill a process using kill command in Linux. And i cannot use Kill -9 to kill the process. can any one please help.

It state is most probably D then, the only state in which kill -9 won't work. Most of the time the only fix is remount the filesystem or reboot.

You can kill the running processes in linux by using kill -9 processId provided that you have right privileges to stop the process. Provide more information if you need more help.

Related

How to see if a process is suspended in unix

I'm trying to resume all processes that are suspended ,but i have no idea how to check if a process is suspended. I tried but it dose not indicate if the process is suspended or running.
You might use Ipor's way (/proc/<pid>/status) if you are using Linux but a more portable solution that should work with most Unix/Unix likes OSes would be to use a standard command as Barmar already suggested in a comment:
ps -o s= -p <pid>
This will show T for a suspended process (also if stopped because being debugged).
Examining process with pid $pid is easy:
if grep -q "^State.*stopped" /proc/$pid/status; then
echo Process $pid is sleeping
else
echo Process $pid is active
fi

How to quickly kill java processes in bash?

On a linux box, I have at most 3 java jars files running. How do I quickly kill all 3 with one command?
Usually I would:
ps ex - get the processes running
then find the process ids then do:
kill -9 #### #### ####
Any way to shorten this process? My eyes hurts from squinting to find the process ids.
My script does the following:
nohup ./start-gossip &
nohup ./start &
nohup ./start-admin &
Is there a way to get the process ids of each without looking it up?
Short answer:
pkill java
This looks up a process (or processes) to kill by name. This will find any other java processes too, so be careful. It also accepts -9, but you should avoid using -9 unless something is really broken.
EDIT:
Based on updates, you may be able to specify the script names to pkill as well (I'm not positive). But, the more traditional way to handle this issue is to leave pid files around. After you start a new process and background it, its pid is available in $!. If you write that pid to a file, then it's easy to check if the process is still running and kill just the processes you mean to. There is some chance that the pid will be reused, however.
You can save the PIDs when you start the processes so you can use them later:
nohup ./start-gossip &
START_GOSSIP_PID=$!
nohup ./start &
START_PID=$!
nohup ./start-admin &
START_ADMIN_PID=$!
...
kill -9 $START_GOSSIP_PID
kill -9 $START_PID
kill -9 $START_ADMIN_PID
This has the advantage (over pkill) of not killing off any other processes that coincidentally have similar names. If you don't want to perform the kill operation from the script itself, but just want to have the PIDs handy, write them to a file (from the script):
echo $START_GOSSIP_PID > /some/path/start_gossip.pid
Or even just do this when you launch the process, rather than saving the PID to a variable:
nohup ./start-gossip &
echo $! > /some/path/start_gossip.pid
To get the process id of that java process run
netstat -tuplen
Process ID (PID) of that process whom you want to kill and run
kill -9 PID

bash & linux symbols, Jboss

I'm writing a script to start Jboss, load an application, send requests to the application, shutdown jboss and repeat. However I dont know how to shut Jboss down from the script. At the moment I'm using
pkill -9 java
But I dont think this is right, because it kills the process, not shut it down. Is there a way to shut it down similar to pressing CTRL-C?
You want a simple
pkill java
From the man page:
pkill will send the specified signal (by default SIGTERM) to each
process
SIGTERM will send a termination signal to the process. If the process is well-written, it will catch this signal and perform an orderly shutdown. If that fails, that's when you can use SIGKILL (-9) which is a forceable termination with no chance for the process to catch and perform cleanup.
Never use kill -9 <PID> by default. It breaks things up, like file descriptors and such.
Start to run kill <PID> alone, default is -15 signal.
See
man 7 signal
And In what order should I send signals to gracefully shutdown processes?
NOTE
kill or pkill doesn't change things so much, same signals are trigered
What you actually want is:
pkill -f jboss
using pkill java could kill any other processes using java on the box.

How to replicate CTRL+C in a shell script?

I'm running a script that performs a command that lasts too long, so I want to interrupt it. Any help? I've tried to search a lot, and I've been pointed to the kill command. Although, I can't get it to work. By the way, I'm using a Mac OS X. Thanks!
Assuming you have the process' PID, send it a SIGINT signal:
kill -SIGINT PID
If you don't have the PID you can try pkill or killall, but they're somewhat less safe; a PID is the only way to uniquely identify a process. Right after you spawn the other process the PID should be in $!, so you can save it then
process-that-takes-a-long-time &
pid=$!
# other stuff
kill -SIGINT $pid
timeout 10 your_command
To replicate Linux Ctrl+C on a terminal on Mac OS X, use ctrl+C!
Its the same keystroke combination
Worked for me (first Steps on Mac)
edit: I didnt read the script is running in background.

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