A.J. Clark

Solutions Architect

Archive for September 2009

Show limits of a running process in Linux

without comments

A rather simple but often asked question was put forward to me today: How can I see the maximum amount of file descriptors my running process can open? (without killing the process!)

Typically one would say ‘check ulimit -n’ but lets say that a thread-driven or event-driven application like varnish or lighttpd is configured with an arbitrary amount of open file descriptors and you want to verify that they have taken effect before the application crashes.

A simple way to check this (atleast on Linux 2.6.26-1 or later) is to run:

svr1:~# awk ‘/Max open files/{ print $4}’ /proc/$(pgrep -n apache)/limits
1024
svr1:~# awk '/Max open files/{ print $4}' /proc/$(pgrep -n lighttpd)/limits

1024

As you can see the above command returned the value of max open files for the running process. This means you can be sure that your lighttpd or varnish application will not suddenly die after being starved of file descriptors!

I have included the entire output of the limits table for the lighttpd process for completeness:

svr1:~# cat /proc/$(pgrep -n lighttpd)/limits
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            ms
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytes
Max resident set          unlimited            unlimited            bytes
Max processes             5824                 5824                 processes
Max open files            1024                 1024                 files
Max locked memory         32768                32768                bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       5824                 5824                 signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0
Max realtime priority     0                    0
Max realtime timeout      unlimited            unlimited            us

Written by napta2k

September 29, 2009 at 2:23 pm

Posted in Linux, lighttpd

Error: Device 0 (vif) could not be connected. Hotplug scripts not working

without comments

Are you running Xen / “xm create” and you get this error?

Try this (RHEL/CentOS): service haldaemon start

- and have a nice day!

Written by napta2k

September 25, 2009 at 7:43 pm

Posted in Linux, Red Hat, Xen