How to measure actual memory usage of an application or process?

How do you measure the memory usage of an application or process in Linux as ps is not an accurate tool to use for this intent.

Why ps is “wrong”?

Depending on how you look at it, ps is not reporting the real memory usage of processes. What it is really doing is showing how much real memory each process would take up if it were the only process running. Of course, a typical Linux machine has several dozen processes running at any given time, which means that the VSZ and RSS numbers reported by ps are almost definitely “wrong”.

With ps or similar tools you will only get the amount of memory pages allocated by that process. This number is correct, but:

  • does not reflect the actual amount of memory used by the application, only the amount of memory reserved for it
  • can be misleading if pages are shared, for example by several threads or by using dynamically linked libraries

If you really want to know what amount of memory your application actually uses, you need to run it within a profiler. For example, valgrind can give you insights about the amount of memory used, and, more importantly, about possible memory leaks in your program.

Setting locale to en_US.UTF-8 failed

While trying to install Owncloud I encountered the following error:
Setting locale to en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8 failed

Please install one of theses locales on your system and restart your webserver.
For Debian Linux the solution is very simple, just run the following command:
dpkg-reconfigure locales
And mark at least one of the locales you need.

How to resolve the ‘/bin/rm: Argument list too long’ error

While you are deleting some files which fill up your disk you may hit -bash: /bin/rm: Argument list too long error message.

So you can use below syntax to can delete those files:
# find . -name "DIR_PATH/*" -type f -exec rm -f {} \;
or:
# find DIR_PATH -name "*" -type f -exec rm -f {} \;

You can also delete files with a specific extension (ex.: .php):
# find DIR_PATH -name "*.php" -type f -exec rm -f {} \;
or:
# find . -name "DIR_PATH/*.php" -type f -exec rm -f {} \;

PS: In our case DIR_PATH=/var/spool/postfix/maildrop (there are like a half million files in that directory).

How to find the number of files on a filesystem?

For some reason df -h command shows that you have plenty of free space. However your apps keep telling you that you don’t have enough free space. The following will help you identify the problem.

The –inodes option to df will tell you how many inodes are reserved for use. For example:
df --inodes /
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/mapper/root
989296 977987 11309 99% /
find / -xdev -print | wc -l
859714

Notice that the number of entries returned from find is lower than IUsed for the root (/) filesystem.

Remember that directories, symlinks, UNIX domain sockets and named pipes are all ‘files’ as it relates to the filesystem. So using find -type f flag is wildly inaccurate, from a statistical viewpoint.

imagick Cannot locate header file MagickWand.h

For some odd reason I did not understand why imagick 2.3.0 did not want to install with ImageMagick 6.8.9-7. Apparently the directory structure changed in the last versions of ImageMagick.

The solution is pretty simple:
ln -s /usr/local/include/ImageMagick-6 /usr/local/include/ImageMagick

After this just follow the next steps and you’re in business:
wget http://pecl.php.net/get/imagick-2.3.0.tgz
pecl install imagick-2.3.0.tgz

I’m running PHP 5.3.28, however keep in mind that this particular version of imagick (2.3.0) won’t work in PHP 5.4 and higher.