Operating System - HP-UX
1826915 Members
3704 Online
109705 Solutions
New Discussion

Re: Asynchronous/synchronous commands

 
SOLVED
Go to solution
Raul del Castillo
Contributor

Asynchronous/synchronous commands

Sorry if this group is not the correct but I have not found any shell group.

I am interested in execute synchronous commands from kshell-script in a asynchronuos mode. I mean, launch them ( with exec?) wait a time a see the results. I know the system calls mechanisms (fork , wait) but I do not know how to make it in a shell script languaje

Any idea? Thanks in advance
3 REPLIES 3
Andreas Voss
Honored Contributor

Re: Asynchronous/synchronous commands

Hi,

to start in background (posix/korn shell):
command &
Waiting for terminating of command:
wait

Regards
Andreas Voss
Honored Contributor
Solution

Re: Asynchronous/synchronous commands

Hi, again,

in korn shell you can also do async reading:

command |&

read -p line

The |& statement executes the command in background.
With read -p you can read the output of the command.
Typically you can do this in a loop:
while read -p line
do
# do anything with the var $line
done

Regards
James R. Ferguson
Acclaimed Contributor

Re: Asynchronous/synchronous commands

Hi:

If you did an 'exec' of a command or of another script, within a script; or an exec of a script or a command at a shell prompt; you will never execute anything afterwards. A successful call to exec() does not return because the new program overwrites the calling program.

As Andreas said, start the process in the background and wait as necessary.

...JRF...