fork example - Korn shell

fork example - Korn shell

am 06.06.2007 23:21:10 von Prateek

Hi,
I have done fork programming using C language. But being new to Korn
shell scripting, I was wondering if I can use Korn shell scripting for
fork. If YES, can someone please provide me a snippet to get started
with.

Thanks,
Prateek

Re: fork example - Korn shell

am 07.06.2007 01:02:13 von cfajohnson

On 2007-06-06, Prateek wrote:
> Hi,
> I have done fork programming using C language. But being new to Korn
> shell scripting, I was wondering if I can use Korn shell scripting for
> fork. If YES, can someone please provide me a snippet to get started
> with.

Use an ampersand to put the job into the background:

COMMAND ARGS &

--
Chris F.A. Johnson, author
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence

Re: fork example - Korn shell

am 07.06.2007 15:18:22 von Walt Fles

On Jun 6, 6:02 pm, "Chris F.A. Johnson" wrote:
> On 2007-06-06, Prateek wrote:
> > Hi,
> > I have done fork programming using C language. But being new to Korn
> > shell scripting, I was wondering if I can use Korn shell scripting for
> > fork. If YES, can someone please provide me a snippet to get started
> > with.
>
> Use an ampersand to put the job into the background:
>
> COMMAND ARGS &
>
> --
> Chris F.A. Johnson, author
> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
> ===== My code in this post, if any, assumes the POSIX locale
> ===== and is released under the GNU General Public Licence

And then capture $! - which is the process ID of the background job
you just forked.
Then you can check the status of $! to see when it finishes:


COMMAND ARG &
background_pid=$!