Sunday, June 30, 2013

Controlling Linux Processes

In my last post, I discussed about viewing linux processes.
Today you will learn how to controll linux processes.

If you run command from terminal, It is attached process OR foreground process.

for exiting from current process, Press Control+C (Ctrl+C). The process will be terminated.

For example, run gedit command. it will open gedit program and this program is attached with your current terminal.
You can not do anything in this terminal without closing this program. So, for closing this program Press Ctrl+C into your terminal.
The running gedit program is closed now.

If you need to run any program in background or detached from the terminal, you can add "&" at the end of the command.
For Example: run "gedit &". it will open gedit and it is detached from the terminal. The terminal should show you it's pid number which you need to close this program.

if you have run multiple background program using "&" and if you need to see all jobs, run "jobs" command.
it will show you all jobs with it's job ID.
Now if you want to attach the terminal to the 2nd program, run fg %2
If you want to attach the terminal to the 1st program, run fg %1
After attaching the program you can simply press Ctrl+C to terminate the program.

Similary you can use bg %1 to move foreground to background.
run gedit and then Press Ctrl+Z. it will stop the program but will not terminate. then move it to background with bg command.

If you want to kill a program run kill [pid]. example kill 4935 here 4935 is the process id.
You can also use job id to kill a program. example: kill %1

To see process and it's pid use ps [ Check my previous post for details ]

To terminate all instances of a program, run "killall programName". example: killall gedit
it will terminate all gedit instances.

Sunday, June 16, 2013

How to view Linux processes

Today I will discuss about Linux processes.

In linux every process has a uniq process ID (PID).
When Linux boot, some processes run in background.
and /sbin/init this is a process which run when the OS boot before any other process
and then daemons process run. /sbin/init this process ID (PID) is always 1.

If we want to see current running process we can do it with the following command


The above command will show only process from current user.
if you want to see all processes, use following command

ps -A

If you want to see all details of each process, run the followinc command

ps aux

if you want to see process from specific user, like process run by user sadiq

ps -u sadiq

If you want to see real-tim view of running process, you can use top command


use q or Esc for exiting top program. you can use htop for more interactive result.
htop is not installed by default. you need to install it. For installing htop, you need to install EPEL repository first.

For Redhat / CentOS 5
rpm -Uvh
rpm -Uvh

for Redhat / CentOS 6
rpm -Uvh
rpm -Uvh

And then run the following command to install htop

yum install htop

When htop is installed, use htop command to see top process list.

Follow my next post to learn about controlling processes.

Thursday, June 13, 2013

Installing APC (Alternate PHP Cache) on CentOS / Redhat

First we need the pecl command to install apc.

run the following command

yum install php-pear

And we need the following command for phpize command

yum install php-devel

We also need to run the following command to enable apxs command

yum install httpd-devel

And then run the following command

yum install pcre-devel

For Debian User

aptitude install libpcre3-dev

And then finally run the pecl install command

pecl install apc

Once finishes, we need to enable apc in apache configuration, run the following command to include extension into php.ini

echo "" > /etc/php.d/apc.ini

Then restart the apache

service httpd restart

That's it. Now enjoy and watch for less execution time compared to before.

Wednesday, June 5, 2013

Freeing up memory cache for Linux OS

The Linux OS has very good RAM management system.
It free up cached memory when it needs.
But if you need to free up memory by force, you
can apply following command

sync; echo 3 > /proc/sys/vm/drop_caches

If you want to do it automatically, run a cron job to do it automatically.

create a file "" with the following content

sync; echo 3 > /proc/sys/vm/drop_caches

Then create a cronjob like

0 * * * * /root/

It will now run every hour and clear memory cache.