Sponsored Content
Top Forums UNIX for Advanced & Expert Users daemonize a process using ksh Post 302217669 by rein on Wednesday 23rd of July 2008 10:06:33 AM
Old 07-23-2008
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.
 

10 More Discussions You Might Find Interesting

1. 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

2. Programming

With daemonize() throwing exception.

I have a function for daemonize() and then I call this to my main(). Here below is my main... int main(int argc, char **argv) { daemonize(); try{ ............ if(fail()) throw Exception(...) ......... } catch (const Exception& e) { cout<< (e.toString()); return -1 } here if... (4 Replies)
Discussion started by: SamRoj
4 Replies

3. UNIX for Advanced & Expert Users

Find the process was run using nohup or ksh.

Hi, I want to write a script which should be run only on foreground. Is there any way that the script can check itself whether it was run using nohup or ksh and if the user runs the script using nohup then it should prompt the user to run it using ksh? If (The user triggers the script using... (4 Replies)
Discussion started by: RRVARMA
4 Replies

4. 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

5. Shell Programming and Scripting

ksh script to process grep output

Hi, I would like to know how can i pipe the following output of grep into a predefined output format This is the output of the grep command grep record *.txt | sort -r 2010-04-28-11-12-21.txt:C The user has created a record 2010-04-29-10-18-41.txt:U The user has updated a record... (8 Replies)
Discussion started by: alienated
8 Replies

6. Shell Programming and Scripting

Help extracting process name from ps command AIX using KSH

Hi All, Newbie script writer and I need some help! I'm grepping ps - eno THREAD >outfile This gives me loads of stuff including the proc names which appear at the end of the line. They're all 10 characters long so what I want to do is cut them (and only them) from the file and put it in... (7 Replies)
Discussion started by: Grueben
7 Replies

7. Shell Programming and Scripting

Script in KSH to check if a process its up or down.

Hi all! Im working on a simple script in KSH (just started) to check if a process its up or down, but im kind of lost with the following error. Script: #!/usr/bin/ksh psup=$(ps -ef | grep sftp | egrep -v grep | wc -l) if ($psup > 0); then echo "Process SFTP running" else ... (6 Replies)
Discussion started by: ARSport
6 Replies

8. 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

9. Shell Programming and Scripting

ksh script to check if certain process is running

I have to kill the process "test" for a maintenance I do but want the script to check when it comes back up. I can get what I want when I run this while loop: while true;do ps -ef | grep test | grep -v grep | sed -e 's/^*//';sleep 60;done but I want the script to do it for me and as soon as... (6 Replies)
Discussion started by: seekryts15
6 Replies

10. Shell Programming and Scripting

Grep for process in a ksh script

Hi I'm trying to catch a particular process (XYZ) running using a ksh script. Like So.. VarPS=`ps -ef |grep XYZ |grep -v grep` However this seems to find the process of the script itself - not the process 'XYZ' Asked in Error - I found my own typo... thanks anyway Skrynesaver (1 Reply)
Discussion started by: Mudshark
1 Replies
let(1)								   User Commands							    let(1)

NAME
let - shell built-in function to evaluate one or more arithmetic expressions SYNOPSIS
ksh let arg... ksh93 let [expr...] DESCRIPTION
ksh Each arg is a separate arithmetic expression to be evaluated. ksh93 let evaluates each expr in the current shell environment as an arithmetic expression using ANSI C syntax. Variables names are shell vari- ables and they are recursively evaluated as arithmetic expressions to get numerical values. let has been made obsolete by the ((...)) syn- tax of ksh93(1) which does not require quoting of the operators to pass them as command arguments. EXIT STATUS
ksh ksh returns the following exit values: 0 The value of the last expression is non-zero. 1 The value of the last expression is zero. ksh93 ksh93 returns the following exit values: 0 The last expr evaluates to a non-zero value. >0 The last expr evaluates to 0 or an error occurred. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
ksh(1), ksh93(1), set(1), typeset(1), attributes(5) SunOS 5.11 2 Nov 2007 let(1)
All times are GMT -4. The time now is 05:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy