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. – Dereleased Nov 06 '09 at 22:43
-
Which OS are you running memcached on? – ss. Nov 06 '09 at 22:45
-
Linux - I should have specified. – barclay Nov 06 '09 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. – barclay Nov 06 '09 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,897
- 4
- 23
- 28
Try
netstat -ap | grep TheChosenPort#
and see if anything is listening on those TCP or UDP ports.

- 1,158
- 5
- 22
- 32

- 23,901
- 4
- 30
- 30
-
quick question, if there's something on port 8080 and you grep '80', wont that give a false positive? – Kieren Johnstone Oct 24 '11 at 19:07
-
2Fyi this doesn't work on OS-X. (the question was for Linux) Try simoes answer. – B Robster Nov 29 '12 at 01: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.

- 155,785
- 88
- 678
- 743
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.

- 3,123
- 6
- 36
- 49
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

- 89,080
- 21
- 111
- 133