Set Terminal tab title in Mac OS X

Picture 2

I wrote previously a how-to to set your iTerm tab title.

I finally found a tool to do the same thing with the default Mac OS X Terminal.

Check it out here, it works perfectly for me!

This entry was written by CharlyBr, posted on August 11, 2009 at 2:12 pm, filed under Command line and tagged , . Leave a comment or view the discussion at the permalink.

Memory usage by group of processes

While monitoring a http/php server, I needed to do some statistics about php-cgi memory usage.

Playing with memory_limit in PHP, we wanted to know the average memory usage per php-cgi process. This is easily calculated with our best friend awk.

First, get the number of php running processes:

# ps aux | grep php-cgi | grep -v grep | wc -l
126

Then, use awk to calculate the average memory usage for these processes:

# ps aux | grep --exclude=grep php-cgi | grep -v grep | awk 'BEGIN{s=0;}{s=s+$6;}END{print s/126;}'
33987.8

The number used in the calculation is the field RSS given by ps. The ps manual page says:

rss: resident set size, the non-swapped physical memory that a task has used (in kiloBytes)

You can also calculate the total memory used by all php-cgi processes:

# ps aux | grep --exclude=grep php-cgi | grep -v grep | awk 'BEGIN{s=0;}{s=s+$6;}END{print s;}'
4302028

If you need to watch the trend of this average memory usage, a little shell loop does the trick:

# while [ 1 ]; do ps aux | grep --exclude=grep php-cgi | grep -v grep | awk 'BEGIN{s=0;}{s=s+$6;}END{print s/126;}'; sleep 2; done
34401.3
34405.1
34408.4
34409.4
34414.2
34417

This entry was written by CharlyBr, posted on March 13, 2009 at 4:14 pm, filed under Benchmarks, Command line, Monitoring and tagged , , , . Leave a comment or view the discussion at the permalink.

The unix touch command

This post is a quick ref on the linux touch command. All the examples have been tested on Linux.

This command is used to update the access and modification times of files.

  • touch’s syntax
touch [option] file_name(s)
touch file1 file2 file3
  • Here some examples:
# touch /tmp/file
# ls -l /tmp/file
rw-r--r-- 1 charlybr charlybr 0 Sep 10 16:13 /tmp/file
  • Update access and modification time to current time:
# ls -l /tmp/file
rw-r--r-- 1 charlybr charlybr 0 Sep 10 16:13 /tmp/file
# touch /tmp/file
# ls -l /tmp/file
rw-r--r-- 1 charlybr charlybr 0 Sep 10 16:14 /tmp/file
  • Update access and modification time to a specified timestamp ([[CC]YY]MMDDhhmm[.ss] format):
# touch -t 09091842 /tmp/file
# ls -l /tmp/file
-rw-r--r-- 1 charlybr charlybr 0 Sep  9 18:42 /tmp/file
  • Update access and modification time to a specified date
# touch -d '9 Sep' /tmp/file
# ls -l /tmp/file
-rw-r--r-- 1 charlybr charlybr 0 Sep  9 00:00 /tmp/file
# touch -d '9 Sep 2008 13:14' /tmp/file
# ls -l /tmp/file
-rw-r--r-- 1 charlybr charlybr 0 Sep  9 13:14 /tmp/file

Links

This entry was written by CharlyBr, posted on September 11, 2008 at 7:30 am, filed under Command line and tagged , . Leave a comment or view the discussion at the permalink.

sudo: port: command not found

On MacOSX, if you have installed macports with the package installer, you may encounter the sudo: port: command not found problem.

Macports binaries are installed in /opt/local/bin, so you just need to add this path to your PATH environment variable. Example with your user, add to your $HOME/.profile :

export PATH=$PATH:/opt/local/bin

You can source your profile file to update your environment:

$ source .profile

You are now able to use the port command:

$ sudo port -v selfupdate

This entry was written by CharlyBr, posted on August 5, 2008 at 12:28 pm, filed under Mac and tagged , , . Leave a comment or view the discussion at the permalink.