Current instance of Shell ignoring SIGTERM


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Current instance of Shell ignoring SIGTERM
# 1  
Old 11-10-2012
Current instance of Shell ignoring SIGTERM

Hello.

Could anyone tell me how can I configure a instance of Shell to ignore the SIGTERM signal? I would really appreciate.

Thanks.
# 2  
Old 11-10-2012
use the trap statement
Code:
trap 'echo "SIGTERM RECEIVED"' 15
# rest of code ....

# 3  
Old 11-10-2012
Quote:
Originally Posted by jim mcnamara
use the trap statement
Code:
trap 'echo "SIGTERM RECEIVED"' 15
# rest of code ....

Well this should make the shell ignore the SIGTERM signal right? It kind of doesnt..
# 4  
Old 11-10-2012
Code:
trap "" TERM

should work on recent systems; if TERM isn't recognized on your system, find the signal number for SIGTERM on your system by looking in your compilation environment's equivalent of /usr/include/sys/signal.h. On most systems SIGTERM will be signal #15 so:
Code:
trap "" 15

will ignore SIGTERM in your script.
# 5  
Old 11-10-2012
trap is used to trap signals within a *running script*. So while your script is running, it can catch a signal received (except for SIGKILL).
However, when you fork a new process from within your script it has its own PID with its own signals. So something like this won't do what you want:

Code:
#!/bin/bash

trap 'echo trapped' SIGTERM
/bin/bash -i  #will fork a new process, parent script keeps running and doesn't get to process the signal received until this child process is finished and flow returns to the script
echo Done #you won't see this until /bin/bash is finished. If this script  received a SIGTERM, you will see the trap message before "Done"

AFAIK it is not possible to catch a signal sent to a running executable, without inserting the trap into its source code and recompiling.

So what you see (guessing, since you never posted your code on how you are calling the shell and how you specify the trap), is that shell process is forked with its own PID, and parent script that you are calling it waiting for it to finish before it can process the signals. You can see that by running the example above.
# 6  
Old 11-11-2012
Code:
kill -l    # -l == lowercase ell

lists all of the signals your system supports, both name and number. /usr/include/sys/signal.h also has them if you want to know what they mean - as Don C mentioned.
# 7  
Old 11-11-2012
Quote:
Originally Posted by jim mcnamara
Code:
kill -l    # -l == lowercase ell

lists all of the signals your system supports, both name and number. /usr/include/sys/signal.h also has them if you want to know what they mean - as Don C mentioned.
The kill -l option originated in the C shell and was standardized by the POSIX standards and the Single UNIX Specification many years ago. The standard requires that the -l option on a command line with no operands list the names of the signals known on that system, but does not allow the signal numbers to also be included in that list. Older versions of the Korn shell did print both names and numbers, but David agreed with other developers writing the standards that having the numbers made it more difficult for shell script writers to process the output of this option. Recent versions of the ksh utility's kill built-in do not print the signal numbers. Smilie

On older systems where the trap special built-in utility only accepts signal numbers (not signal names), it was common practice for the kill utility not to recognize the -l option either.

You can also use current versions of the kill utility to translate a signal number into a signal name. For example:
Code:
kill -l $((128 + 15))

will either print TERM or SIGTERM on systems where signal number 15 is SIGTERM. Obviously, you can also put the above command in a loop to map signal numbers to signal names on your system.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh child process not ignoring SIGTERM

My ksh version is ksh93- =>rpm -qa | grep ksh ksh-20100621-3.fc13.i686 I have a simple script which is as below - #cat test_sigterm.sh - #!/bin/ksh trap 'echo "removing"' QUIT while read line do sleep 20 done I am Executing the script From Terminal 1 - 1. The ksh is started... (3 Replies)
Discussion started by: rpoornar
3 Replies

2. Shell Programming and Scripting

Need help in getting the oracle instance name which is offline in 10g through shell scripting

:wall:Hi, I am not sure whether i can post this question in this forum or not. because it is not completely releated to unix, but also oracle. My question is, How can we know the instance name(particularly the last number, eg., in INST_DB12, i need 12) when it is OFFLINE(i.e., down)... (1 Reply)
Discussion started by: Dpu
1 Replies

3. Shell Programming and Scripting

Need help in writing a shell Script to connect to oracle instance

Please help me in writing a shell script which connects to a Oracle instance and tables to get the required information...:wall: (1 Reply)
Discussion started by: Dpu
1 Replies

4. UNIX for Advanced & Expert Users

Multiple Instance of Unix Shell Script

Hi All, I have a problem mentioned below. I have a script which performs line by line operations on several files. I have a temp_file storing the list of names of the file to be validated. Right not in while loop i validate these files one by one. Is there anyway that i can modify... (1 Reply)
Discussion started by: amitaryans
1 Replies

5. Shell Programming and Scripting

Monitoring Tomcat Instance using shell script

Hello Forum, I have prepared script to monitor the tomcat status. Following is the script which will monitor tomcat instance.I need little modifcation in the script. My script will grep for java,the output of grep command will analyze by if condition under for loop and will send following echo... (7 Replies)
Discussion started by: coolguyamy
7 Replies

6. Shell Programming and Scripting

fetch hostname and instance name using shell script

Hi All, Requirement is to fetch hostname and instance name using shell script from all configuration files on a server R12 on IBM AIX... could anyone please share such an experience encountered before.Is there such a script available in this forum or any other site.. Thanks for your time!... (0 Replies)
Discussion started by: a1_win
0 Replies

7. Shell Programming and Scripting

How to run a new shell with copy of current shell declarations?

How to run another shell and have all current shell dectaration copied to that new shell? I would like to have available all current declarations in a new shell. That are functions, aliases, variables. I need to test some functions that use the 'exit', but running it in current shell on... (9 Replies)
Discussion started by: alex_5161
9 Replies

8. Shell Programming and Scripting

replace first instance(not first instance in line)

Alright, I think I know what I am doing with sed(which probably means I don't). But I cant figure out how to replace just the first occurance of a string. I have tried sed, ed, and grep but can't seem to figure it out. If you have any suggestions I am open to anything! (3 Replies)
Discussion started by: IronHorse7
3 Replies

9. Shell Programming and Scripting

Single Instance of a Shell Script

Hi, I have a shell script. What should I do to allow only single instance of the script to be run by a user at a time. That is, Only one user can run that script at a given point of time. Please help.. Its very important for my project Thanks in advance (4 Replies)
Discussion started by: pathanjalireddy
4 Replies

10. Programming

signals - SIGTERM

Hi all, I need some urgent help. we are using Dynix/ptx V4.5 on i386, have several processes and instances are running on the box round the clock.we increased the processes recently. We have coded to handle the signals in our programs. Recently, we noticed most of our processes are... (2 Replies)
Discussion started by: reddyb
2 Replies
Login or Register to Ask a Question