So far, I have used "processId": {command: PickProcess} ", maybe it's not the best method, but it always worked." Unfortunately, this method has not worked for a few days. (Please see attachment)
In the console I get "Starting inspector on 127.0.0.1:9229 failed: address already in use".
I have not figured out what the problem is. Can someone give me a hint?
I was facing the same issue on my linux machine.
Ran lsof -i :9229 command to find which process is using port 9229
Then ran kill -9 <process id using the port>
Its usually extension manager, then restart
Alternatively, you can open process manager in vs code and kill extension host
Then restart vscode and try to debug by using attach to process id
For windows:
C:\Users\Niroshan>netstat -ano|findstr "PID :8080"
Proto Local Address Foreign Address State PID
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 18264
taskkill /pid 18264 /f
as mentioned in this answer:
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.
I've written a scrip that works fine to start and stop a server.
#!/bin/bash
PID_FILE='/var/run/rserve.pid'
start() {
touch $PID_FILE
eval "/usr/bin/R CMD Rserve"
PID=$(ps aux | grep Rserve | grep -v grep | awk '{print $2}')
echo "Starting Rserve with PID $PID"
echo $PID > $PID_FILE
}
stop () {
pkill Rserve
rm $PID_FILE
echo "Stopping Rserve"
}
case $1 in
start)
start
;;
stop)
stop
;;
*)
echo "usage: rserve {start|stop}" ;;
esac
exit 0
If I start it by running
rserve start
and then start monit it will correctly capture the PID and the server:
The Monit daemon 5.3.2 uptime: 0m
Remote Host 'localhost'
status Online with all services
monitoring status Monitored
port response time 0.000s to localhost:6311 [DEFAULT via TCP]
data collected Mon, 13 May 2013 20:03:50
System 'system_gauss'
status Running
monitoring status Monitored
load average [0.37] [0.29] [0.25]
cpu 0.0%us 0.2%sy 0.0%wa
memory usage 524044 kB [25.6%]
swap usage 4848 kB [0.1%]
data collected Mon, 13 May 2013 20:03:50
If I stop it, it will properly kill the process and unmonitor it. However if I start it again, it won't start the server again:
ps ax | grep Rserve | grep -vc grep
1
monit stop localhost
ps ax | grep Rserve | grep -vc grep
0
monit start localhost
[UTC May 13 20:07:24] info : 'localhost' start on user request
[UTC May 13 20:07:24] info : monit daemon at 4370 awakened
[UTC May 13 20:07:24] info : Awakened by User defined signal 1
[UTC May 13 20:07:24] info : 'localhost' start: /usr/bin/rserve
[UTC May 13 20:07:24] info : 'localhost' start action done
[UTC May 13 20:07:34] error : 'localhost' failed, cannot open a connection to INET[localhost:6311] via TCP
Here is the monitrc:
check host localhost with address 127.0.0.1
start = "/usr/bin/rserve start"
stop = "/usr/bin/rserve stop"
if failed host localhost port 6311 type tcp with timeout 15 seconds for 5 cycles
then restart
I had problem start or stop process via shell too.
One solution might be add "/bin/bash" in the config like this:
start program = "/bin/bash /urs/bin/rserv start"
stop program = "/bin/bash /urs/bin/rserv stop"
It worked for me.
monit is a silent killer. It does not tell you anything. Here are things I would check which monit won't help you identify
Check permissions of all the files you are reading / writing. If you are redirecting output to a file, make sure that file is writable by uid and gid you are using to execute the program
Again check exec permission on the program you are trying to run
Specify full path to any program you are trying to execute ( not strictly necessary, but you don't have to worry about path not being set if you always specify full path )
Make sure you can run the program outside of monit without any error before trying to investigate why monit is not starting.
If the Monit log is displaying
failed to start (exit status -1) -- no output
Then it may be that you're trying to run a script without any of the Bash infrastructure. You can run such a command by wrapping it in /bin/bash -c, like so:
check process my-process
matching "my-process-name"
start program = "/bin/bash -c '/etc/init.d/my-init-script'"
When monit starts it checks for its own pidfile and checks if the process with
matching PID is running already - if it does, then it just wakes up this
process.
in your case, check if this pid is being used by some other process:
ps -ef |grep 4370
if yes, then you need to remove the below file(usually under /run directory) and start monit again:
monit.pid
For me, the issue was that the stop command was not being run, even though I specifically specified "then restart" on the configuration.
The solution was just to change:
start program = "/etc/init.d/.... restart"
I opened port #5955 from a java class to comunicate from a client. How do i close this port after I am done? and also which command can show me if port open or closed?
Find out the process ID (PID) which is occupying the port number (e.g., 5955) you would like to free
sudo lsof -i :5955
Kill the process which is currently using the port using its PID
sudo kill -9 PID
To find the process try:
sudo lsof -i :portNumber
Kill the process which is currently using the port using its PID
kill PID
and then check to see if the port closed. If not, try:
kill -9 PID
I would only do the following if the previous didnt work
sudo kill -9 PID
Just to be safe. Again depending on how you opened the port, this may not matter.
EDIT
In 09/2022 this helped me for MacOS Monterey M1 Pro Chip:
sudo lsof -t -i tcp:yourPortNumber | sudo xargs kill
In 2018 here is what worked for me using MacOS HighSierra:
sudo lsof -nPi :yourPortNumber
then:
sudo kill -9 yourPIDnumber
very simple find port 5900:
sudo lsof -i :5900
then considering 59553 as PID
sudo kill 59553
However you opened the port, you close it in the same way. For example, if you created a socket, bound it to port 0.0.0.0:5955, and called listen, close that same socket.
You can also just kill the process that has the port open.
If you want to find out what process has a port open, try this:
lsof -i :5955
If you want to know whether a port is open, you can do the same lsof command (if any process has it open, it's open; otherwise, it's not), or you can just try to connect to it, e.g.:
nc localhost 5955
If it returns immediately with no output, the port isn't open.
It may be worth mentioning that, technically speaking, it's not a port that's open, but a host:port combination. For example, if you're plugged into a LAN as 10.0.1.2, you could bind a socket to 127.0.0.1:5955, or 10.0.1.2:5955, without either one affecting the other, or you could bind to 0.0.0.0:5955 to handle both at once. You can see all of your computer's IPv4 and IPv6 addresses with the ifconfig command.
One liner is best
kill -9 $(lsof -i:PORT -t) 2> /dev/null
Example :
On mac, wanted to clear port 9604. Following command worked like a charm
kill -9 $(lsof -i:9604 -t) 2> /dev/null
You can also use this first command to kill a process that owns a particular port:
sudo netstat -ap | grep :<port_number>
For example, say this process holds port 8000 TCP, then running the command:
sudo netstat -ap | grep :8000
will output the line corresponding to the process holding port 8000, for example:
tcp 0 0 *:8000 *:* LISTEN 4683/procHoldingPort
In this case, procHoldingPort is the name of the process that opened the port, 4683 is its pid, and 8000 (note that it is TCP) is the port number it holds (which you wish to close).
Then kill the process, following the above example:
kill 4683
As others mentioned here out, if that doesn't work (you can try using kill with -9 as an argument):
kill -9 4683
Again, in general, it's better to avoid sending SIGKILL (-9) if you can.
Find the process ID using command
lsof -n -i4TCP:8080
After getting the processId
sudo kill -9 processID
Then provide your system password.
I have created a function for this purpose.
function free_port() {
if [ -z $1 ]
then
echo no Port given
else
PORT=$1;
PID=$(sudo lsof -i :$PORT) # store the PID, that is using this port
if [ -z $PID ]
then
echo port: $PORT is already free.
else
sudo kill -9 $PID # kill the process, which frees the port
echo port: $PORT is now free.
fi
fi
}
free_port 80 # you need to change this port number
Copy & pasting this block of code in your terminal should free your desired port. Just remember to change the port number in last line.
I use lsof combined with kill, as mentioned above; but wrote a quick little bash script to automate this process.
With this script, you can simply type killport 3000 from anywhere, and it will kill all processes running on port 3000.
https://github.com/xtrasimplicity/killport
Simple One-liner
There is a way more straightforward command today, than the other ones (without Sudo, packages or multiple lines)
To kill port 8080 simply call:
lsof -ti tcp:8080 | xargs kill
This seem to work for me. Just change your_port_number into the port number you want to stop.
sudo lsof -t -i tcp:your_port_number | xargs kill -9
try below, assuming running port is 8000:
free-port() { kill "$(lsof -t -i :8000)"; }
I found the reference here
When the program that opened the port exits, the port will be closed automatically. If you kill the Java process running this server, that should do it.
First find out the Procees id (pid) which has occupied the required port.(e.g 5434)
ps aux | grep 5434
2.kill that process
kill -9 <pid>
I am using JMeter for load testing and some of my threads just hang. I want to do a thread dump but none of the following work from my linux machine
First get JMeter process id using
jps -l
Then did
sudo -u <username> jstack <pid>
and get the following msg
15141: Unable to open socket file: target process not responding or HotSpot VM not loaded
The -F option can be used when the target process is not responding
even
kill -3 15141
comes up with nothing
After lot of googling and trial and error found the solution
To take thread dumps, start JMeter using command line.
Open terminal (A)
$ cd /media/9260C06E60C05A9D/Downloads/jakarta-jmeter-2.4/bin
$ ./jmeter > temp
In another terminal (B)
Get the process id of JMeter
$ jps -l
$ kill -QUIT 21735
Now check temp file for thread dump.
In order to use jstack make sure the user and group user are the same as the user running jstack