I have been running a server with:
go run server.go &
When I am done with the process, this requires me to kill the process. The way I have been doing this is with kill PID of the go run process.
However, I've noticed my server appears connected still. Investigating further it seems that there are other processes go is starting which appear to "keep alive" my server:
$ps aux | grep go
username 70481 0.0 0.0 573416816 5228 ?? S 3:15PM 0:00.63 /var/folders/wf/89r2567s5hv48lj1g9l65mbw0000gp/T/go-build062422854/command-line-arguments/_obj/exe/server
username 70472 0.0 0.0 573407408 7720 ?? S 3:15PM 0:00.80 go run server.go
When I kill this associated process, too, I see that my connection is released as expected.
Is there a better way to "really" kill a golang process than kill PID? Or is there a reason why there are these phantom processes?
I have resorted to killing both but this seems... strange.
$ go version
go version go1.5.4 darwin/amd64
The one you're calling the "phantom process" is your server, which is why killing it kills your server. The other is the "go run" utility itself, which is compiling your code and then running the resulting executable.
I am wondering if we can stop a Single JVM within specific time limit. If it is not stopping within that time limit then kill the process from shell script.
If we are executing ./stopServer.sh JVM_Name - It will run till the jvm will not get stopped or till any error and exit.
What I am trying to do is :./stopServer.sh JVM_Name - If this do not stopped within 2 min(suppose), then kill the process (But How to figure out it is not stopped within 2 mins through shell script before the process go for killing). I can write the condition to kill . But not sure how to do checks if the JVM stopped within 2 mins or not so that we can go ahead to kill process.
Can anyone please suggest shell script code to identify if the jvm is stopped within specific time limit or not?
A JVM is a process and as such can be stopped with the kill command - kill $processid or more brutal kill -9 $processid
If you start the JVM from a script using something like java ... then I suggest putting a & at the end of that line and in the following line
processid=$!
which saves the id of the background process.
Then
sleep 120
will wait for 2 min.
Now you have two options - either just kill
kill $processid /dev/null 2>&1
or first check if the processid might (very unlikely) be reused by another process (or use some other way to check if your JVM has finished, maybe a file that indicates this from your java program) and then if it matches use the kill.
ps -ef|grep -w $processid |grep -w java > /dev/null
If it has returncode zero then continue with the kill
test $? -eq 0 && kill $processid
I usually would trust that the processid is either my JVM or not used at all
I would like to find a way to find the process id of a Jenkins job, so I can kill the process if the job gets hung. The Jenkins instance is on Ubuntu. Sometimes, we are unable to stop a job via the Jenkins interface. I am able to stop a job by killing the process id if I run a Jenkins job that contains a simple shell script where I manually collect the process id such as:
#!/bin/bash
echo "Process ID: $$"
for i in {1..10000}
do
sleep 10;
echo "Welcome $i times"
done
In the command shell, I can run sudo kill -9 [process id]and it successfully kills the job.
The problem is, most of our jobs have multiple build steps and we have multiple projects running on this server. Many of our build steps are shell scripts, windows batch files, and a few of them are ant scripts. I'm wondering how to find the process id of the Jenkins job which is the parent process of all of the build steps. As of now, I have to wait until all other builds have completed and restart the server. Thanks for any help!
On *nix OS you can review environment variables of a running process by investigating a /proc/$pid/environ and look for Jenkins specific variables like BUILD_ID, BUILD_URL, etc.
cat /proc/'$pid'/environ | grep BUILD_URL
You can do it know you $pid or go through of running processes.
This is an update to my question. For killing hung (zombie) jobs, I believe that this will only work for cases where Jenkins is running from the same server as its jobs. I doubt this would work if you are trying to kill a hung process running on a Jenkins slave.
#FIND THE PROCESS ID BASED ON JENKINS JOB
user#ubuntu01x64:~$ sudo egrep -l -i 'BUILD_TAG=jenkins-Wait_Job-11' /proc/*/environ
/proc/5222/environ
/proc/6173/environ
/proc/self/environ
# ONE OF THE PROCESSES LISTED FROM THE EGREP OUTPUT IS THE 'EGREP'COMMAND ITSELF,
# ENSURE THAT (LOOP THROUGH) THE PROCESS ID'S TO DETERMINE WHICH IS
# STILL RUNNING
user#ubuntu01x64:~$ if [[ -e /proc/6173 ]]; then echo "yes"; fi
user#ubuntu01x64:~$ if [[ -e /proc/5222 ]]; then echo "yes"; fi
yes
# KILL THE PROCESS
sudo kill -9 5222
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.
I tried kill -9 698 but the process did not die.
$ ps -ef | grep chromium
502 698 811 0 0:01.24 ?? 0:07.28 /Users/lucius/chromium/src/xcodebuild/Debug/Chromium.app/Contents/MacOS/Chromium
502 854 732 0 0:00.00 ttys001 0:00.00 grep chromium
$ kill -9 698
$ ps -ef | grep chromium
502 698 811 0 0:01.24 ?? 0:07.28 /Users/lucius/chromium/src/xcodebuild/Debug/Chromium.app/Contents/MacOS/Chromium
502 854 732 0 0:00.00 ttys001 0:00.00 grep chromium
If you're trying to kill -9 it, you have the correct PID, and nothing happens, then you don't have permissions to kill the process.
Solution:
$ sudo kill -9 PID
Okay, sure enough Mac OS/X does give an error message for this case:
$ kill -9 196
-bash: kill: (196) - Operation not permitted
So, if you're not getting an error message, you somehow aren't getting the right PID.
Some cases you might want to kill all the process running in a specific port. For example, if I am running a node app on 3000 port and I want to kill that and start a new one; then I found this command useful.
Find the process IDs running on TCP port 3000 and kill it
kill -9 `lsof -i TCP:3000 | awk '/LISTEN/{print $2}'`
If you know the process name you can use:
killall Dock
If you don't you can open Activity Monitor and find it.
Do you can list the process using a port with command lsof, for example:
lsof -i tcp:PORT_NUMBER_HERE
Replace the word PORT_NUMBER_HERE to the port number that you are using, then a the process running on the port will be listed. Then you have just to kill the process ID founded like this:
kill PID_NUMBER
Where PID_NUMBER is the process ID running on the port.
If kill -9 isn't working, then neither will killall (or even killall -9 which would be more "intense"). Apparently the chromium process is stuck in a non-interruptible system call (i.e., in the kernel, not in userland) -- didn't think MacOSX had any of those left, but I guess there's always one more:-(. If that process has a controlling terminal you can probably background it and kill it while backgrounded; otherwise (or if the intense killing doesn't work even once the process is bakcgrounded) I'm out of ideas and I'm thinking you might have to reboot:-(.
I just now searched for this as I'm in a similar situation, and instead of kill -9 698 I tried sudo kill 428 where 428 was the pid of the process I'm trying to kill. It worked cleanly for me, in the absence of the hyphen '-' character. I hope it helps!
Given the path to your program, I assume you're currently running this under Xcode, and are probably at a debug breakpoint. Processes cannot be killed in this state because of the underlying implementation of breakpoints.
The first step would be to go to your Xcode process and stop debugging. If for some strange reason you have lost access to Xcode (perhaps Xcode has lost access to its gdb sub-process), then the solution is to kill the gdb process. More generally, the solution here is to kill the parent process. In your case this is PID 811 (the third column).
There is no need to use -9 in this case.
I have experienced that if kill -9 PID doesn't work and you own the process, you can use kill -s kill PID which is kind of surprising as the man page says you can kill -signal_number PID.
in the spotlight, search for Activity Monitor. You can force fully remove any application from here.
I recently faced similar issue where the atom editor will not close. Neither was responding. Kill / kill -9 / force exit from Activity Monitor - didn't work. Finally had to restart my mac to close the app.