How to detect Hanged process in shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to detect Hanged process in shell script?
# 1  
Old 12-24-2013
How to detect Hanged process in shell script?

I have to check daily 20 processes each day. The names are like Network1 Network2 Network3 ....... Network20.
There is built in utility for doing this. Following is the command to check a single network process.
Code:
 check_process_status 1

If we want to check the status of Network2 then the commands is
Code:
 check_process_status 2

If network process is running then this command gives a very long o/p.
But if that process is hanged or having some problems then the command will not give any o/p. The session will remain ideal until I press Ctrl+C

How can find the network processes which are hanged. I need to get the process name for which
Code:
 check_process_status

dont give any o/p and gets stuck there. Checking for 20 processes daily is tedious job. Please help me
# 2  
Old 12-24-2013
Unless you give us more details, answers will be vague as well.
You could run all checks in background, with output redirection, and check the output file size after some time. You also could check the process list for that 20 processes and see what state they are in to decide which are running and which are hung.
# 3  
Old 12-24-2013
Thanks for your reply. While checking it manauly i do following. Lets assume i am checking Network2 process following is the command.

Code:
check_process_status 2

After entering the command i wait for 4-5 seconds. If the output (which is very long) doesn't come then i have to enter ctrl+c to come back to command prompt of UNIX.
I want to find out for which processes this scenario is happening. i.e. I want to find out for which processes i would have pressed ctrl+c.
# 4  
Old 12-24-2013
Try this
Code:
for p in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
do
 perl "alarm 15; exec @ARGV" check_process_status $p >/dev/null ||
 echo pkill Network$p
done

Remove the echo to really run the pkill.
# 5  
Old 12-24-2013
Thanks for your reply.
Just wanted to confirm: I am working in Ksh. So will that command work?
alarm 15 will wait for 15 sec ?
Also what is pkill command is used for? does it act like ctrl+c ?

Sorry but i am new to shell scripting so please help
# 6  
Old 12-24-2013
In perl alarm 15 will send a SIGALRM to itself after 15 seconds. It immediately execs into the check_process_status, so this will be killed!
(While Ctrl-C sends SIGINT.)
The pkill is for terminating the corresponding Network process.
(kill and pkill send SIGTERM by default.)
# 7  
Old 12-24-2013
Thank you for such a good explanation... But that command is not working for unix server for my application. Smilie
Is it possible by using wait command?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to detect which process is run by what?

Hello, I am running under ubuntu 14.04 Very long time ago, I set a script (ban.sh) to block ip addresses abusing my system which was not active. I have not touched the server over six months or more. Today, after restart the system, ban.sh started running all of a sudden and keep submitting... (4 Replies)
Discussion started by: baris35
4 Replies

2. Shell Programming and Scripting

Detect current shell inside a script

I wish to print my current shell which happens to be bash in my script check.sh more check.sh echo $0 echo `ps -p $$` But instead of printing it prints check.sh i.e the name of the script for both the commands. Can you please suggest how to print the current shell i m on inside the... (2 Replies)
Discussion started by: mohtashims
2 Replies

3. Shell Programming and Scripting

How to detect that foreground process is waiting for input?

Hi, I have to create a script (ksh or perl) that starts certain number of parallel jobs (another scripts), each of them runs as a foreground process in a separate session. Plus I start monitoring job that has to determine if any of those scripts is expecting input from operator, and switch to... (4 Replies)
Discussion started by: andyh80
4 Replies

4. Shell Programming and Scripting

How to detect key press in cgi shell script?

I want to detect key pressed in my .cgi web page, but it does not work even I found the code in other web site. My code is : #!/bin/sh #================================================= # PATH defination # ================================================... (2 Replies)
Discussion started by: Shuinvy
2 Replies

5. Shell Programming and Scripting

Shell Script to Kill Process(number of process) Unix/Solaris

Hi Experts, we do have a shell script for Unix Solaris, which will kill all the process manullay, it used to work in my previous env, but now it is throwing this error.. could some one please help me to resolve it This is how we execute the script (and this is the requirement) ... (2 Replies)
Discussion started by: jonnyvic
2 Replies

6. Solaris

How to know about a hanged process

Hi, My process is visible in 'ps' command but actually it is not working or it got hanged. This process is not generating any log. Now How can I know that my process got hanged. Please help. (2 Replies)
Discussion started by: sanjay1979
2 Replies

7. Shell Programming and Scripting

Need your HELP:: Shell script to detect paragraph in coordinate-based code.

Hi Friends!! I have obtained following output from a tool called pdftoxml: <xml> <text top="423" left="521" width="333" height="20" font="3">Although the the number of fuzzy rules of a system is </text> <text top="441" left="500" width="355" height="20" font="3">directly dependant on these... (2 Replies)
Discussion started by: parshant_bvcoe
2 Replies

8. Shell Programming and Scripting

While killing the process, Script gets hanged. Please help me on this.

Hi Everyone, I have written a script to automate the docbase cleanup process on every weekly basis. That is in this script i have to shutdown the docbase and then kill all the process that are hanged except one process(epic process) and need to delete some log files and then i have to start the... (8 Replies)
Discussion started by: Sheethal
8 Replies

9. HP-UX

how to check whether a script is running actively or hanged/ in deadlock)

Hi I have a doubt regarding process states in HP unix system. Is there a way to check whether a process is hanged or still actively running? I have few scripts which run for a long time. but sometimes these are getting hanged. But i'm never sure whether they are running or waiting in kind of... (4 Replies)
Discussion started by: truth
4 Replies

10. Shell Programming and Scripting

How to detect process

Dear Sir, Now I use oracle database on AIX server and found some user use iligal program such as development tool logon to my database. I want to detect the process of illegal program and kill it. Could you please suggest me to make detect process. Thank you very much Pkanonwe. (2 Replies)
Discussion started by: pkanonwe
2 Replies
Login or Register to Ask a Question