Shell script not exiting Gracefully


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script not exiting Gracefully
# 1  
Old 02-07-2007
Shell script not exiting Gracefully

Hi
we are seeing strange behaviour , when we execute shell script it is successfully executing but it's PID is still hanging when we see ps -ef | grep script1.ksh until we do Kill <PID>


$script1.ksh
$
$ ps -ef | grep script1.ksh
user1 249996 1 0 10:48:40 pts/1 0:00 /usr/bin/ksh script1.ksh

Inside script we are using
exit command before completion of script



OS : AIX 5.3.0.0

Can someone advise

Let me know if you need any additional information .


thanks
SmithK
# 2  
Old 02-07-2007
Hard to tell if you don't provide the code of the script.
# 3  
Old 02-07-2007
I have narrowed down the issue we are using gzip in the script ..to compress the file ..we write to the pipe then we will compreess using gzip
below is the sample code

#!/usr/bin/ksh

/usr/sbin/mknod NAMEDPIPE p

gzip -1 < NAMEDPIPE > EXPORT &
db2 "export to NAMEDPIPE of del select * from test" ##db2 command to
## export data
rm -f NAMEDPIPE


After completion of the script , successfully , i still see the script PID , i don't see connection any connection to DB , Basically script is hanging in there doing nothing , I suspect gzip -1 < NAMEDPIPE > EXPORT & not termenating ....properly

Thanks
Smithk
# 4  
Old 02-07-2007
Quote:
Originally Posted by smithK
I have narrowed down the issue we are using gzip in the script ..to compress the file ..we write to the pipe then we will compreess using gzip
below is the sample code

#!/usr/bin/ksh

/usr/sbin/mknod NAMEDPIPE p

gzip -1 < NAMEDPIPE > EXPORT &
db2 "export to NAMEDPIPE of del select * from test" ##db2 command to
## export data
rm -f NAMEDPIPE


After completion of the script , successfully , i still see the script PID , i don't see connection any connection to DB , Basically script is hanging in there doing nothing , I suspect gzip -1 < NAMEDPIPE > EXPORT & not termenating ....properly

Thanks
Smithk
In your script you create a background process which reads from the named pipe (gzip).

Next you start a process (db) which writes to the named pipe.

As soon as the writing process (db) is done you remove the named pipe.

Most likely by that time the reading process (gzip) did not yet complete reading all data from the named pipe.

Since the named pipe (and the data in it) has been removed the reading process will never receive an EOF.

Basically the reading process is left with an open file descriptor which refers to something that doesn't exist any more.

Therefore the gzip command will not terminate.

Since this process is a child process of your script, your script will not terminate.

It only seems as if it terminated, all it did was returning controll back to your shell. Underneath it's waitingfor a dead of child.

After executing your script, I expect you will not only be able to find your script with ps in the process table, but the gzip as well.

Furthermore, I do understand why you use a NAMED pipe for something like this.

Wouldn't it be much easier to use:

db2 "export to EXPORT of del select * from test"
gzip -1 EXPORT

I'm not familiar with the db command, but I assume
db2 " select * from test"
would produce the output to your screen.

If so, why not use an "anonymous" pipe:
db2 "select * from test" | gzip -1 - > EXPORT.gz

It might work with a NAMED pipe as well if you switch the 2 commands:
:
#!/usr/bin/ksh

/usr/sbin/mknod NAMEDPIPE p

db2 "export to NAMEDPIPE of del select * from test" & ##db2 command to
## export data
gzip -1 < NAMEDPIPE > EXPORT.gz

rm -f NAMEDPIPE
# 5  
Old 02-08-2007
I think yes
gzip -1 < NAMEDPIPE_FILE > EXPORT_FILE &

causing the issue , we are writting to the pipe since we don't have enough space on filesystem to export data , we write data into Pipe and then compress in the background .

we can't do like this
db2 "export to NAMEDPIPE of del select * from test" &
gzip -1 < NAMEDPIPE > EXPORT.gz

Since if we hvae any error on export like table not found ... next step gzip is waitting for the PIPEFILE , and script itself is hanging without proceeding to next step.


Any insight ?

thanks
smithk
# 6  
Old 02-08-2007
You could try to build a delay before removing the pipe.

sleep 30
rm -f NAMEDPIPE
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exiting from Minicom on a shell script

This is what I've tried: #!/bin/sh send sh send showifs send exit ! killall minicom My problem is that for some reason when I do this it doesn't give me the results of the prior commands sent like showifs So I suspect my syntax is wrong. (1 Reply)
Discussion started by: uradunce
1 Replies

2. Programming

Closing Socket Gracefully Solaris

Hi All I am creating one client socket with SO_LINGER option Disabled struct linger LingerState = {0, 0}; if (setsockopt(_hSocketTCP, SOL_SOCKET, SO_LINGER, (const char *) &LingerState, sizeof(struct linger)) == -1) { cout<<"Cannot set linger to 0 for socket"<<endl... (0 Replies)
Discussion started by: mr_deb
0 Replies

3. Solaris

Unable to install Sol10 on V245, exiting to shell.

Hi there, OK so I am super-green, but I have a problem I am hoping someone can help me with. I have a V245 that I am unable to install Solaris 10 (10/09) onto as during the initial install process, the UI pops up for region selection, but then as I enter my region, identify the system, up comes... (21 Replies)
Discussion started by: wallrunn3r
21 Replies

4. Shell Programming and Scripting

Exiting out of the script

I have to write a script in ksh which again should call another script. Say A.ksh is calling B.ksh. Now in B.ksh if the condition we are checking for is true then we have to go back to the main script A.ksh or if the condition in B.ksh is false then we have to totally come out of the scripts. I... (1 Reply)
Discussion started by: vpv0002
1 Replies

5. Shell Programming and Scripting

"Odd" behavior exiting shell script

Is it normal behavior for a shell script that terminates to terminate its parent shell when executed with the "." option? For example, if I have the example script (we'll name it ex.sh): #!/bin/sh if then echo "Bye." exit 2 fi And I execute it like this: >./ex.sh It... (6 Replies)
Discussion started by: DreamWarrior
6 Replies

6. Shell Programming and Scripting

exiting from script

Hi, I am trying to exit the script from a function. I was in assumption that if we use exit ( inside or outside the function) it will exit from the script. alternatively, return will exit from that particular function. but in my case, exit is exiting from the function and not the script.... (8 Replies)
Discussion started by: shellwell
8 Replies

7. Shell Programming and Scripting

shell script exiting before completing

I have a script which has the following statement, /opt/oracle/product/9i/bin/sqlplus << EOC >> $LOG_FILE 2>&1 username/password ---- Enters the SQL prompt @/export/home/oracle/shells/grant_userview.sql ---Runs the SQL script @/export/home/oracle/shells/grant_proc_userview.sql ---Runs the... (6 Replies)
Discussion started by: welldone
6 Replies

8. Shell Programming and Scripting

Exiting a script

I have a script abc.sh. Its contents are as follows: (7 Replies)
Discussion started by: lassimanji
7 Replies

9. Shell Programming and Scripting

Shell script..invoking command and exiting at fixed intervals

Hi, I need to write a shell script. Based on command line param to script say demode=yes Need to run an ant command for an hour(configurable) Then exit Again run the ant command all this needs to be in a loop. Thanks in advance Raj (1 Reply)
Discussion started by: rajuak12
1 Replies

10. Shell Programming and Scripting

exiting from script

there are many script in my project.i am having a problem when i am trying to quit from child script.what is the command to wrap up all the parent script and calling script as well? exit 0 is not working.please help.... (1 Reply)
Discussion started by: arghya_owen
1 Replies
Login or Register to Ask a Question