ksh child process not ignoring SIGTERM


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh child process not ignoring SIGTERM
# 1  
Old 06-27-2013
ksh child process not ignoring SIGTERM

My ksh version is ksh93-
Code:
  =>rpm -qa | grep ksh 
ksh-20100621-3.fc13.i686

I have a simple script which is as below -
Code:
#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 from /bin/ksh as below :
Code:
# exec /bin/ksh

2. The script is executed from this ksh-
Code:
# ./test_sigterm.sh&
[1] 12136

and Sending a "SIGTERM" From Terminal 2 -
Code:
# ps -elf | grep ksh 
4 S root     12136 30437  0  84   4 -  1345 poll_s 13:09 pts/0    00:00:00 /bin/ksh ./test_sigterm.sh
0 S root     18952 18643  0  80   0 -  1076 pipe_w 13:12 pts/5    00:00:00 grep ksh
4 S root     30437 30329  0  80   0 -  1368 poll_s 10:04 pts/0    00:00:00 /bin/ksh

# kill -15 12136

I can see that my test_sigterm.sh is getting killed on receiving the "SIGTERM" in either case, when run in background (&) and foreground. But the ksh man pages say - Signals. The INT and QUIT signals for an invoked command are ignored if the command is followed by & and the monitor option is not active. Otherwise, signals have the values inherited by the shell from its parent (but see also the trap built-in command below).
Is it a know or default behaviour of ksh to NOT IGNORE SIGTERM? or is an issue with ksh child SIGTERM signal handling?

Last edited by pludi; 06-27-2013 at 09:45 AM.. Reason: Code part not
# 2  
Old 06-27-2013
I find nothing unusual in the behavior you describe; only an interactive shell should ignore SIGTERM. As kill's default signal, SIGTERM wouldn't be very useful if it were widely ignored.

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 3  
Old 06-28-2013
Quote:
Originally Posted by rpoornar
My ksh version is ksh93-
Code:
  =>rpm -qa | grep ksh 
ksh-20100621-3.fc13.i686

I have a simple script which is as below -
Code:
#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 from /bin/ksh as below :
Code:
# exec /bin/ksh

2. The script is executed from this ksh-
Code:
# ./test_sigterm.sh&
[1] 12136

and Sending a "SIGTERM" From Terminal 2 -
Code:
# ps -elf | grep ksh 
4 S root     12136 30437  0  84   4 -  1345 poll_s 13:09 pts/0    00:00:00 /bin/ksh ./test_sigterm.sh
0 S root     18952 18643  0  80   0 -  1076 pipe_w 13:12 pts/5    00:00:00 grep ksh
4 S root     30437 30329  0  80   0 -  1368 poll_s 10:04 pts/0    00:00:00 /bin/ksh

# kill -15 12136

I can see that my test_sigterm.sh is getting killed on receiving the "SIGTERM" in either case, when run in background (&) and foreground. But the ksh man pages say - Signals. The INT and QUIT signals for an invoked command are ignored if the command is followed by & and the monitor option is not active. Otherwise, signals have the values inherited by the shell from its parent (but see also the trap built-in command below).
Is it a know or default behaviour of ksh to NOT IGNORE SIGTERM? or is an issue with ksh child SIGTERM signal handling?
The SIGTERM signal isnt being caught as it isnt SIGINT or SIGQUIT as the manpage says. If monitor option is off "set +o monitor" then sending a "kill -INT <pid>" or "kill -QUIT <pid>" wont terminate your job but not if you send a "kill -TERM <pid>" to it...
This User Gave Thanks to shamrock For This Post:
# 4  
Old 06-28-2013
As alister already said, the default signal handling behavior for SIGTERM is to terminate the process. Since you haven't ignored SIGTERM in your current shell and you don't ignore SIGTERM in test_sigterm.sh, test_sigterm.sh should terminate the process and that is exactly what you're describing. If you need test_sigterm.sh to ignore SIGTERM signals, change test_sigterm.sh from:
Code:
  #!/bin/ksh
trap 'echo "removing"' QUIT 
while read line
do
sleep 20
done

to:
Code:
#!/bin/ksh
trap '' TERM
trap 'echo removing' QUIT 
while read line
do
        sleep 20
done

Note that in addition to adding a trap to ignore SIGTERM, I:
  1. moved the #!/bin/ksh to the start of the line (with it where it was, the default shell for your system will be used to run this script instead of the Korn shell),
  2. removed the double quotes around removing (there is no need to quote a single word operand to the echo utility), and
  3. indented the body of the while loop (to make it easier to see the structure of your shell script).
This User Gave Thanks to Don Cragun For This Post:
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. Shell Programming and Scripting

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. (6 Replies)
Discussion started by: razolo13
6 Replies

3. Shell Programming and Scripting

forking a child process and kill its parent to show that child process has init() as its parent

Hi everyone i am very new to linux , working on bash shell. I am trying to solve the given problem 1. Create a process and then create children using fork 2. Check the Status of the application for successful running. 3. Kill all the process(threads) except parent and first child... (2 Replies)
Discussion started by: vizz_k
2 Replies

4. Emergency UNIX and Linux Support

signal between parent process and child process

Hello, everyone. Here's a program: pid_t pid = fork(); if (0 == pid) // child process { execvp ...; } I send a signal (such as SIGINT) to the parent process, the child process receive the signal as well as the parent process. However I don't want to child process to receive the... (7 Replies)
Discussion started by: jackliang
7 Replies

5. Shell Programming and Scripting

[KSH/Bash] Starting a parent process from a child process?

Hey all, I need to launch a script from within 2 other scripts that can run independently of the two parent scripts... Im having a hard time doing this, if anyone knows how please let me know. More detail. ScriptA (bash), ScriptB (ksh), ScriptC (bash) ScriptA, launches ScriptB ScirptB,... (7 Replies)
Discussion started by: trey85stang
7 Replies

6. Shell Programming and Scripting

How to make the parent process to wait for the child process

Hi All, I have two ksh script. 1st script calls the 2nd script and the second script calls an 'C' program. I want 1st script to wait until the 'C' program completes. I cant able to get the process id for the 'C' program (child process) to make the 1st script to wait for the second... (7 Replies)
Discussion started by: sennidurai
7 Replies

7. Programming

the parent receive SIGTERM from its child (httpd) ?

the parent is a process manager in our design, and httpd service is one of its child processes, which is started in foreground mode (with "-D FOREGROUND" options) according to our requirements. when httpd service is started, one main httpd process and eight sub httpd processes can be found by... (4 Replies)
Discussion started by: aaronwong
4 Replies

8. Programming

Can SIGTERM to main process kill the detached threads?

Hi, I am stuck up with a strange problem. I am writing an application - a kinda tracker that reads data from memcache and invokes theads to process each record of the memcache. I dont want to join all my threads because my tracker should poll the cache in regular intervals say sum 300... (2 Replies)
Discussion started by: deepti_v25
2 Replies

9. Shell Programming and Scripting

Killing child process in ksh

I have a script that (ideally) starts tcpdump, sleeps a given number of seconds, then kills it. When I do this for 10 seconds or and hour, it works fine. When I try it for 10 hours (the length I actually want) it just doesn't die, and will actually stick around for days. Relevant part of my... (1 Reply)
Discussion started by: upnix
1 Replies

10. Shell Programming and Scripting

In ksh, how does an in-line child sub-process get its own PID?

This is not the same as a few of the other posted items dealing with sub-process pids (that I saw anyway). If zot contains: echo "main mypid: $$ - lastpid: $!" ( echo "block mypid: $$ - lastpid: $! - ppid: $PPID" ps -ef > xxx sleep 5 echo "block mypid: $$ - lastpid: $! - ppid:... (6 Replies)
Discussion started by: MichLab
6 Replies
Login or Register to Ask a Question