RE: [suse-programming-e] call a script in a script
On Tuesday, May 17, 2005 2:23 AM, William A. Mahaffey III wrote:
Patrick B. O'Brien wrote:
Using ksh.
I want to call script_B from script_A.
I don't not want script_A to hang around for script_B to finish.
I tried bg but no joy. Script_A sits and waits for script_B to finish before moving on; which is no good. Any thoughts and thank you.
inside script_A:
(script_B &)
The parentheses may not be required, my man page was for ksh on SGI, I don't have it on my SuSE 8.2 box. YMMV & all that.
Whilst this will work (although I have worked on systems where the parent process still hangs around), it's not very efficient... The parentheses create a new process which in turn creates a new process for script_B (because of the &). On some systems (e.g. cygwin on Windows), process creation carries a hefty price. Far better is to use the ksh builtin exec command which replaces the current process (i.e. "ksh script_A") with the new process (i.e. ksh script_B). So, instead of the above, just: exec script_B
From the ksh man page:
exec [argument ...](1) If argument is given, the command specified by the arguments is executed in place of this shell without creating a new process. Input/output arguments can appear and affect the current process. HTH, Phil -- ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. www.mimesweeper.com **********************************************************************
Phil Betts wrote:
On Tuesday, May 17, 2005 2:23 AM, William A. Mahaffey III wrote:
Patrick B. O'Brien wrote:
Using ksh.
I want to call script_B from script_A.
I don't not want script_A to hang around for script_B to finish.
I tried bg but no joy. Script_A sits and waits for script_B to finish before moving on; which is no good. Any thoughts and thank you.
inside script_A:
(script_B &)
The parentheses may not be required, my man page was for ksh on SGI, I don't have it on my SuSE 8.2 box. YMMV & all that.
Whilst this will work (although I have worked on systems where the parent process still hangs around), it's not very efficient...
The parentheses create a new process which in turn creates a new process for script_B (because of the &). On some systems (e.g. cygwin on Windows), process creation carries a hefty price. Far better is to use the ksh builtin exec command which replaces the current process (i.e. "ksh script_A") with the new process (i.e. ksh script_B).
So, instead of the above, just:
exec script_B
From the ksh man page:
exec [argument ...](1) If argument is given, the command specified by the arguments is executed in place of this shell without creating a new process. Input/output arguments can appear and affect the current process.
HTH,
Phil
Hmmmm .... wouldn't that wipe out the current instance of script_A ? I thought he wanted script_A to continue after kicking off script_B .... -- William A. Mahaffey III --------------------------------------------------------------------- Remember, ignorance is bliss, but willful ignorance is LIBERALISM !!!!
Phil, On Tuesday 17 May 2005 01:46, Phil Betts wrote:
On Tuesday, May 17, 2005 2:23 AM, William A. Mahaffey III wrote:
Patrick B. O'Brien wrote:
Using ksh.
I want to call script_B from script_A.
I don't not want script_A to hang around for script_B to finish.
I tried bg but no joy. Script_A sits and waits for script_B to finish before moving on; which is no good. Any thoughts and thank you.
inside script_A:
(script_B &)
The parentheses may not be required, my man page was for ksh on SGI, I don't have it on my SuSE 8.2 box. YMMV & all that.
...
The parentheses create a new process which in turn creates a new process for script_B (because of the &). On some systems (e.g. cygwin on Windows), process creation carries a hefty price. Far better is to use the ksh builtin exec command which replaces the current process (i.e. "ksh script_A") with the new process (i.e. ksh script_B).
True. Parentheses are not simply for grouping (as you say, they create a sub-shell). You get simple grouping of a sequence of commands with {curly braces}. That kind of grouping is merely syntactic (and things like "exit" executed within them will cause the shell interpreting the script to exit. Bailing out of a {curly brace sequence} without exiting the shell that's executing it is what the "return" built-in is for. While what you say about process creation (fork) in Cygwin is true, I don't think we're really considering that here (this is a SuSE list, after all, and Cygwin is owned by RedHat...).
So, instead of the above, just:
exec script_B
Perhaps. Keep in mind that unless the shell that invoked script_A used "script_A &", it will end up waiting for script_B to complete. If you want the parent of script_A to continue on after it (script_A) starts script_B, then you must use "script_B &". "Exec script_B &" is equivalent to "script_B &".
...
Phil
Randall Schulz
participants (3)
-
Phil Betts
-
Randall R Schulz
-
William A. Mahaffey III