Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I wrote a Perl script to grab info (from files such as /proc//stat, /proc//io, /proc//cmdline, ...) of every process on my Linux system periodically (say, every minute). However, when I ran this script, it sometimes hangs on processes that quick disappeared, especially those processes with small ID (due to wrapping around). I did add status checking of every info file before opening it. Anyone could shed some light? Thanks.

share|improve this question
    
When you say "hang", how long does this hang ? If long enough to get diagnostic activity in, then try "cat </proc/kmsg & echo t > /proc/sysrq-trigger" and find the kernel-side stacktrace for the hung perl process in the output written to the system messages logs. Re ... closing this - probably yes, as this is more a sysadmin / debugging question. –  FrankH. Jun 11 '13 at 12:40
    
It hangs forever unless I kill the process. It usually hangs when many processes are created in a sudden (for example, I have a Java code which generates numerous processes) and their process IDs rewind to small numbers. Another thing is that the problem does not happen often, so it is hard to reproduce. Currently my sysadmin set /proc/sys/kernel/sysrq to 0. I guess the sysadmin has to set to 1 in order to try your script. Thanks. –  Li Nick Jun 11 '13 at 19:31
    
If this is some critical production system, then SysRq-T might create some overhead as depending on your console settings, it may hang for a few seconds. Don't do it on something that's HA-clustered. In that case, it's probably better to attach a kernel debugger live and look at the kernel-side stacktraces for your hung script directly; in RHEL crash, that'd be bt <pid>. More straightforward then as well. –  FrankH. Jun 12 '13 at 10:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.