The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 07-23-2008
rein rein is offline
Registered User
  
 

Join Date: Dec 2004
Location: Zürich
Posts: 146
daemonize a process using ksh

I'm trying to create daemon processes with ksh as follows:


Code:
function start 
{
   # start script as co-process and pass an argument
   ./1.ksh $1 |&

   # print pid
   print $!
   
   # move the file descriptors of the co-process to 4 and 5 
   exec 4>&p
   exec 5<&p

   # then close them
   exec 4>&-
   exec 5<&-
}


for server in $servers
do
   start "arg1"
done
If script 1.ksh only contains a sleep, then it works. But if I have multiple statements, several ssh calls that take a while (>10min) for example, than the 1.ksh scripts just exits without finishing. This happens shortly after the calling script has finished. If I keep the calling script open they finish correctly. After the child scripts have finshed the calling script also finishes.I added the following after the call to the start routine:

Code:
while read -ru5 
do
   print -r $line
done
(and I commented out the closing of the file descriptors)

than it works. I want the 1.ksh processes to become daemon processes and finish and I want the calling script to exit.

I run it on a SunOS 5.8 server with ksh 88.