Tuesday, December 26, 2006

rm and the 'Argument list too long'

you wanted to delete all the files in a directory that begins with the word 'temp' bala bala

[prabhat@my-site]# rm temp*
bash: /bin/rm: Argument list too long

ERROR!
This happens when you are trying to delete too many files in a directory at the same time - it seems rm has limits ....

To solve the problem:

Use 'find' to pipe all the matching files to 'rm', one at a time.
[prabhat@my-site]# find . -name 'temp*' | xargs rm

or

[prabhat@my-site]# find . -name 'temp*' - print0 | xargs -0 rm -f

Monday, December 18, 2006

Sort folders by size with one command

Entire user’s data is under /home, I need to have a list of all the sub folders sorted by the size of the sub folders.
simple command to get the list of sub folders sorted by their size:
du --max-depth=1 /home/ | sort -n -r

Friday, December 01, 2006

Zombie Process

A process can be sleeping in kernel code. Usually that's because of faulty hardware or a badly written driver- or maybe a little of both. A device that isn't set to the interrupt the driver thinks it is can cause this, for example- the driver is waiting for something its never going to get. The process doesn't ignore your signal- it just never gets it.
A zombie process doesn't react to signals because it's not really a process at all- it's just what's left over after it died. What's supposed to happen is that its parent process was to issue a "wait()" to collect the information about its exit. If the parent doesn't (programming error or just bad programming), you get a zombie. The zombie will go away if its parent dies- it will be "adopted" by init which will do the wait()- so if you see one hanging about, check its parent; if it is init, it will be gone soon, if not the only recourse is to kill the parent..which you may or may not want to do.
* Finally, a process that is being traced (by a debugger, for example) won't react to the KILL either.

We can find out zombie process by :-
Use top or ps command:
# top
OR
# ps aux | awk '{ print $8 " " $2 }' | grep -w Z


How do I kill zombie process?
You cannot kill zombies, as they are already dead. But if you have too many zombies then kill parent process or restart service.

You can kill zombie process using PID obtained from any one of the above command. For example kill zombie proces having PID 4104:
# kill -9 4104
*Please note that kill -9 does not guarantee to kill a zombie process

How do I automate zombie process killing?
Write a script and schedule as a cron job.
for each in `ps jauxww | grep Z | grep -v PID | awk ‘{print $3}’`; do for every in `ps auxw | grep $each | grep cron | awk ‘{print $2}’`; do kill -9 $every; done; done

SHOW ENGINE INNODB STATUS

  The SHOW ENGINE INNODB STATUS command in MySQL provides detailed information about the internal state of the InnoDB storage engine. This ...