Catching SIG of running process with bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Catching SIG of running process with bash
# 1  
Old 11-15-2009
Catching SIG of running process with bash

Hello all!

I'm writing a script that will catch when an outside process crashes (SIGHUP, right?) without having to loop into infinity.
With that in mind, I came across the trap utility and thought if could be used to monitor another process other than it's own. But from what I've read, I'm thinking it might be more limited than what I initially believed.

Could someone point me in the right direction? Smilie

This is what I have on trap so far:
Traps
trap(1) - Linux man page
# 2  
Old 11-17-2009
Suggested direction: man ps; man fork # Possibly for might return no results - use google then
Suggested improvement: man sh; man ksh; man bash

Extra description:
SIGHUP = SIGnal HangUP. AFAIK it was used in the past when you connected using a modem and then disconnected (hanged up). Now its meaning might be different - check the kernel source (signals.h if I remembered it right).

"trap" might be used to trap almost all the signals (except -9 obviously). The only thing is that it traps your own process - not other processes.

Why would anyone monitor other processes? Some OSes might restrict you so that you wouldn't see processes of other users. Then I assume that you might want to monitor own processes. In such case - check when you are running a new process and store the PID of started process. You might read about PIDs and about pseudo-variables like $!,$$,$PPID. In addition use $?.

You might be unlucky and someone might have created a very nasty code - a code-mine. I am describing code which starts, runs some other process in the background, disowns it forgetting about its PID and then exits (probably without specific return code since such code is usually a crap).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command to get exact tomcat process I am running ignoring other java process

Team, I have multiple batchjobs running in VM, if I do ps -ef |grep java or tomcat I am getting multiple process list. How do I get my exact tomcat process running and that is unique? via shell script? (4 Replies)
Discussion started by: Ghanshyam Ratho
4 Replies

2. UNIX for Advanced & Expert Users

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (6 Replies)
Discussion started by: naveeng
6 Replies

3. UNIX for Advanced & Expert Users

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (1 Reply)
Discussion started by: naveeng
1 Replies

4. BSD

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (0 Replies)
Discussion started by: naveeng
0 Replies

5. Shell Programming and Scripting

Killing a bash process and running the second part of script

I want to run a script that calls remote ssh and if it gets hung, I want to be able to kill that part of the script and run another command in the script for example I have a statement like this: if ]; then export tapes=$(for tape in $(su - nacct -c 'ssh remote1 "cat... (1 Reply)
Discussion started by: newbie2010
1 Replies

6. Shell Programming and Scripting

Bash Question: HowTo Exit Script with User Input While Process is Running Mid-Loop?

Hi, I have written a script that allows me to repetitively play a music file $N times, which is specified through user input. However, if I want to exit the script before it has finished looping $N times, if I use CTRL+c, I have to CTRL+c however many times are left in order to complete the loop.... (9 Replies)
Discussion started by: hilltop_yodeler
9 Replies

7. Shell Programming and Scripting

Quiting running process without catching TRAP signal

Hi, I would like to ask, if is it possible to quit running loop in the script any other way than catching the trap signal. Ctrl-C ends only current running instance of process but not whole script. Any clues? (3 Replies)
Discussion started by: smoofy
3 Replies

8. Shell Programming and Scripting

Bash: Catching the returncode from a script and using within another script?

Hello, I want to run a bash script in another bash script, depending on the returncode or exitcode. But I don't know how to handover the returncode to the second bash script!? I tried this dummy script which should return the exit code 1 #test.sh echo "test" exit 1 But... (3 Replies)
Discussion started by: ABE2202
3 Replies

9. Shell Programming and Scripting

script to monitor process running on server and posting a mail if any process is dead

Hello all, I would be happy if any one could help me with a shell script that would determine all the processes running on a Unix server and post a mail if any of the process is not running or aborted. Thanks in advance Regards, pradeep kulkarni. :mad: (13 Replies)
Discussion started by: pradeepmacha
13 Replies

10. Programming

catching a signal from child process

i am creating children processes using fork system call every child i create goes to sleep for random time. when child stops running how can i catch his signal and turminate the child (2 Replies)
Discussion started by: emil2006
2 Replies
Login or Register to Ask a Question