I am having some problems with memcached and one idea I am having is that perhaps it is already running on the port I am trying to run it on, started by some other user on our network. Is there a way to tell what memcached ports are currently in use?
-
Have you tried connecting to them? Even a denial of access will prove your point.– DereleasedNov 6, 2009 at 22:43
-
Which OS are you running memcached on?– ss.Nov 6, 2009 at 22:45
-
Linux - I should have specified.– barclayNov 6, 2009 at 22:52
-
1Also, when I kill my own memcached process with the port I started it on, and try to connect to the port, I do get a denial of access. I am wondering if a process is hanging in some kind of corrupted state and therefore somehow blocking access to the port.– barclayNov 6, 2009 at 22:54
6 Answers
To see if it is running you could also try telnetting into the port:
telnet localhost 11211
If this works you will see the following (telling you that the given port is open):
Connected to localhost.
Escape character is '^]'.
Now if memcached IS running you can see some basic stats by issuing the given command:
stats
If this fails you will know that memcached is not running.
-
-
4
-
Try
netstat -ap | grep TheChosenPort#
and see if anything is listening on those TCP or UDP ports.
-
quick question, if there's something on port 8080 and you grep '80', wont that give a false positive? Oct 24, 2011 at 19:07
-
2Fyi this doesn't work on OS-X. (the question was for Linux) Try simoes answer. Nov 29, 2012 at 1:01
-
netstat
In Linux, check via netstat
, e.g.
$ sudo netstat -nap | grep memcached
tcp 0 0 127.0.0.1:11211 0.0.0.0:* LISTEN 5067/memcached
ps
Use ps
to filter the processes:
$ ps wuax | grep memcache
497 5067 0.0 1.3 384824 53928 ? Ssl Apr11 1:28 memcached -d -p 11211 -u memcached -m 64 -c 1024 -P /var/run/memcached/memcached.pid -l 127.0.0.1
The port can be found next to -p
, e.g. -p 11211
. If port hasn't been specified, default is 11211
.
Bash
You can send stats
command to the given port and see if the memcached responds, e.g.
exec 3<>/dev/tcp/localhost/11211; printf "stats\nquit\n" >&3; cat <&3
Telnet
Use telnet
to connect to the host and run stats
(as above), e.g.
$ telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
stats
STAT pid 23669
STAT uptime 433859
Then hit Ctrl-] and Ctrl-D to finish.
You can check memcached status
service memcached status
You will see a line like this at the bottom:
└─1560 /usr/bin/memcached -vv -m 64 -p 11211 -u memcache -l 127.0.0.1 -P /var/run/memcached/memcached.pid
The -p 11211 is what port it's running on.
If you're asking this question, it sounds like you're running a really old version. If you did this on a recent version, you'd see this:
% ./memcached
failed to listen on TCP port 11211: Address already in use