Hi
Thanks for the replies.
Here is a flavour of what I am trying to get at:
===========
trap 'sigpipehd' PIPE
function sigpipehd
{
print "Trapped SIGPIPE"
print "The co-process died unexpectedly"
}
function copro
{
{
read x; print $x
}|&
}
function writetocopro
{
print "Writing to copro"
print -p "hi"
return $?
}
function readcopro
{
print "Reading from copro"
read -p y;
print "copro output:" $y
return $?
}
function myfunc
{
print $0: $1
return $1
}
copro
writetocopro &&
readcopro
sleep 5
print
print
writetocopro && readcopro || print "error"
print "The End"
Output:
Writing to copro
Reading from copro
copro output: hi
Writing to copro
copropipe2a.sh[54]: writetocopro[26]: print: no query process [Bad file
descriptor]
error
The End
===========
So in this version SIGPIPE does not come into play at all and the code does
what I want apart from the error recorded at line 54.
What I have been trying to do was to test if the co-process was still there
to I tried this:
===========
trap 'sigpipehd' PIPE
function sigpipehd
{
print "Trapped SIGPIPE"
print "The co-process died unexpectedly"
}
function copro
{
{
read x; print $x
}|&
}
function writetocopro
{
print "Writing to copro"
print -u9 "hi"
return $?
}
function readcopro
{
print "Reading from copro"
read -u8 y;
print "copro output:" $y
return $?
}
function myfunc
{
print $0: $1
return $1
}
copro
exec 8<&p
exec 9>&p
writetocopro
readcopro
sleep 5
print
print
writetocopro && readcopro || print "error"
print "The End"
Output:
Writing to copro
Reading from copro
copro output: hi
Writing to copro
Trapped SIGPIPE
The co-process died unexpectedly
===========
So in the second case the code never comes back to the rest of the
instructions after the signal handler.
Here I was emulating a co-process using builtins, if I call another script
I can indeed catch SIGCHLD, but if I do not catch SIGPIPE the main script
just stops.
The reason in the second example for grabbing hold of the file descriptors,
was in my bigger programme I wanted to have logic that would close them and
then test using /dev/fd/<number> and I could not find a way of doing the
test using "&p".
Regards
Pete
On 8 October 2013 23:06, David Korn <[email protected]> wrote:
> With the older version, the trap can check the pid against $! since $! is
> set to the process that exited. With ksh93v you get more information
> available in the trap.
>
>
>
> On Tue, Oct 8, 2013 at 5:13 PM, Roland Mainz <[email protected]>wrote:
>
>> On Tue, Oct 8, 2013 at 5:02 PM, Peter Hitchman <[email protected]>
>> wrote:
>> > On 6 October 2013 13:44, Cedric Blancher <[email protected]>
>> wrote:
>> >> On 6 October 2013 10:36, Peter Hitchman <[email protected]>
>> wrote:
>> >> > Hi
>> >> > I am using Version JM 93t+ 2010-06-21 on RHL4.
>> >> > I have been playing around with a co-process and what happens when
>> the
>> >> > co-process dies.
>> >> > What I have found is that to have any control I have to catch
>> SIGPIPE in
>> >> > a
>> >> > function,
>> >> > but that I cannot then continue processing outside of this function,
>> all
>> >> > I
>> >> > can do is exit the script.
>> >> >
>> >> > Is this the right way to do it?
>> >>
>> >> Do you have any example code which shows what you are trying to do?
>> >
>> > OK I'll work up a simple example, what I have now is to much to post.
>> > The background is that I am connecting to an Oracle database using
>> sqlplus
>> > as a co-process and seeing what happens when for some reason the db
>> > connection goes away. I found that I had to trap SIGPIPE.
>>
>> Erm... does the example below help somehow (it requires a newer
>> ksh93v- version since .sh.sig is a new feature in that version) ?
>> -- snip --
>> $ ksh -x -c 'builtin pids ; trap "print -v .sh.sig ; kill -l
>> \${.sh.sig.status}" CHLD ; { thispid=${ pids -f "%(pid)d" ; } ; kill
>> -s ABRT $thispid ; } & ; wait ; print $? ; true'
>> + builtin pids
>> + trap 'print -v .sh.sig ; kill -l ${.sh.sig.status}' CHLD
>> + wait
>> + pids -f '%(pid)d'
>> + thispid=1966
>> + kill -s ABRT 1966
>> + print -v .sh.sig
>> (
>> typeset -r -l -i 16 addr=16#3e8000007ae
>> typeset -r -l -i band=0
>> typeset -r code=KILLED
>> typeset -r -i errno=0
>> typeset -r name=CHLD
>> typeset -r -i pid=1966
>> typeset -r -i signo=17
>> typeset -r -i status=6
>> typeset -r -i uid=1000
>> value=(
>> typeset -r -i q=6
>> typeset -r -l -u -i Q=6
>> )
>> )
>> + kill -l 6
>> ABRT
>> + print 1
>> 1
>> + true
>> -- snip --
>>
>> ... it shows a process child killing itself using SIGABORT (kill -s
>> ABRT and uses the pids(1) builtin to figure out the process id of the
>> child process) and the CHLD trap first prints the contents of the
>> .sh.sig compound variable (which is ksh93's variation of the POSIX
>> siginfo data) and then uses the .sh.sig.signo variable to figure out
>> which signal (or better: The name of the signal which...) killed the
>> child process (using $ kill -l ${signal_number} #).
>>
>> ----
>>
>> Bye,
>> Roland
>>
>> --
>> __ . . __
>> (o.\ \/ /.o) [email protected]
>> \__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
>> /O /==\ O\ TEL +49 641 3992797
>> (;O/ \/ \O;)
>> _______________________________________________
>> ast-users mailing list
>> [email protected]
>> http://lists.research.att.com/mailman/listinfo/ast-users
>>
>
>
_______________________________________________
ast-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-users