Unix Shell - co-process in ksh

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > November 2006 > co-process in ksh





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author co-process in ksh
BobbyH

2006-11-21, 7:21 pm

I can create a co-process and read from the process with commands like:
============================
$ cat /etc/passwd |&
$ read -p1 line
$ echo $line
root:x:0:0:Super User:/:/bin/sh
$ read -p1 line
$ echo $line
daemon:x:1:1::/:
$
=============================
My questions are:
1) How can I determine what co-process numbers are open?


AND

2) How can I close a co-process when I have finished using it?

bhiggins@airmail.net


rajesh.tamil.india@gmail.com

2006-11-22, 7:27 am

1. There is only one co-process at a time, if you want to use more than
one, then the input and output should be redirected using >&p <&p.
2. Redirect the input of the co-process by exec 5<&p; exec 5<&-

BobbyH wrote:
> I can create a co-process and read from the process with commands like:
> ============================
> $ cat /etc/passwd |&
> $ read -p1 line
> $ echo $line
> root:x:0:0:Super User:/:/bin/sh
> $ read -p1 line
> $ echo $line
> daemon:x:1:1::/:
> $
> =============================
> My questions are:
> 1) How can I determine what co-process numbers are open?
>
>
> AND
>
> 2) How can I close a co-process when I have finished using it?
>
> bhiggins@airmail.net


Michael Paoli

2006-11-26, 7:18 pm

BobbyH wrote:
> I can create a co-process and read from the process with commands like:
> ============================
> $ cat /etc/passwd |&
> 1) How can I determine what co-process numbers are open?


$!
Either save it immediately after starting your co-process, or if you
haven't started any other co-processes or background/asynchronous
processes, you can still refer to $!. You can also use jobs or jobs
-l to get jobs, and optionally PIDs, but which are co-processes vs.
other asynchronous jobs may not be easy to determine.

> 2) How can I close a co-process when I have finished using it?


"close a co-process"? What are you asking, exactly? You can
redirect and close its stdin and/or stdout, and/or you can terminate
(kill(1)) the process (by PID, or by job with ksh's kill).

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com