How do I see if memcached is already running on my chosen port?

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.


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.


Try

netstat -ap | grep TheChosenPort#

and see if anything is listening on those TCP or UDP ports.

Tags:

Memcached