File descriptors problem perplexing me


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File descriptors problem perplexing me
# 1  
Old 01-24-2005
File descriptors problem perplexing me

Greetings,

I have a troubling problem with a Korn Shell concept that I know works in Solaris.

Essentially I am assigning file descriptors to a coprocess. Also, it should be noted that I am not using the public domain ksh but, rather AT&T ksh93.

Here is a test scenario:

$ sqlplus -s /nolog |& <== Coprocess
[1] 8566
$ print -p "prompt Hello"
$ read -p line
$ print $line
Hello <== proof that the async communication works


$ exec 5>&p <== assign fd 5 to stdout and fd 6 to stdin
$ exec 6<&p
$ print -u5 "prompt Hello again" <== This works in Solaris but not in Linux
ksh: print: bad file unit number <== I don't know why this is occurring
[1] + Done sqlplus -s /nolog |& <== coprocess dies
$ read -u6 line
$ print $line

$ ulimit -a
address space limit (kbytes) (-M) unlimited
core file size (blocks) (-c) 0
cpu time (seconds) (-t) unlimited
data size (kbytes) (-d) unlimited
file size (blocks) (-f) unlimited
locks (-L) unlimited
locked address space (kbytes) (-l) 32
nofile (-n) 65536 <== Should be enough fds available
nproc (-u) 16384
pipe buffer size (bytes) (-p) 4096
resident set size (kbytes) (-m) unlimited
socket buffer size (bytes) (-b) 4096
stack size (kbytes) (-s) 10240
threads (-T) not supported
process size (kbytes) (-v) unlimited

Any ideas why I can't do this in Linux?

Regards,

Thomas
# 2  
Old 01-24-2005
What you're doing looks good to me. I would suspect a bug your linux version of ksh.
# 3  
Old 01-24-2005
Quote:
Originally Posted by Perderabo
I would suspect a bug your linux version of ksh.
I downloaded and manually installed the latest binary version of KSH from AT&T Research Labs. I thought about downloading and compiling the source. I'll give that a try as soon as I can. I was really hoping that someone had experienced something similar and knew the magic kernel parameter. Thanks for the comments.

Thomas
# 4  
Old 01-24-2005
And if that doesn't work try pdksh - I'm running v5.2.14 99/07/13.2 and the example you posted works fine for me.

Cheers
ZB
# 5  
Old 01-24-2005
Quote:
Originally Posted by zazzybob
And if that doesn't work try pdksh - I'm running v5.2.14 99/07/13.2 and the example you posted works fine for me.
I already confirmed prior to posting that pdksh does work fine as you have indicated (even on a PC running CYGWIN). The problem that I encountered with pdksh has to do with variable scope as follows:

$ set -A RESULTS_ARRAY "Initial Value" 0 0 0 0
...
$ {
... some command producing output...
} | while read LINE
> do
> ...
> RESULTS_ARRAY[0]="Some new text"
> RESULTS_ARRAY[1]=1
> ...
> done

$ print ${RESULTS_ARRAY[0]}
Initial Value

The variable's scope appears to be limited to within the while loop. This is probably basic but I could not determine the answer at 2 AM when I was struggling over it. This is when I discovered that I had been using pdksh rather than AT&T's. AT&T's corrected this and I quit persuing it. What technique do I use to broaden the variable's scope? I tried to export the variable with the same results.

Thomas
# 6  
Old 01-26-2005
Quote:
Originally Posted by tmarikle
...The problem that I encountered with pdksh has to do with variable scope as follows:...
...What technique do I use to broaden the variable's scope?....
At least I found why pdksh behaves they way I described. When piping through "while read" loop, everything inside the loop is executed in a subshell. This why my variables were not taking hold.

It may be easier to alter my code to avoide "while read" loops and go back to pdksh than to figure out my file descriptor problem.

Thomas
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Questions about file descriptors

Hi, I'm playing with KSH I entered following command in terminal { echo "stdout" >&1; echo "stderr" >&2; } > out And I get only stoud in a new file out. My question is: Where did my stderr vanish ? (5 Replies)
Discussion started by: solaris_user
5 Replies

2. UNIX for Dummies Questions & Answers

Semaphores and File Descriptors

What is the difference between a file descriptor and a semaphore? My basic understanding is: - a file descriptor is a small positive integer that the system uses instead of the file name to identify an open file or socket. - a semaphore is a variable with a value that indicates the... (1 Reply)
Discussion started by: Mr_Webster
1 Replies

3. HP-UX

exec and file descriptors

Hi, I speak and write english more or less, so I hope my asking be clear. :) In the company I am working, they are using control-m software to lunch shell scripts. So i put this command in all shell scripts: export LOGFILE_tmp=$PRODUC_DATA/tmp/${SCRIPT}_${PAIS}_`date... (0 Replies)
Discussion started by: anamcara
0 Replies

4. UNIX for Advanced & Expert Users

A perplexing mystery

A perplexing mystery... please note that i am not a lacky, and the error below is misleading recently something i do all the time broke (a script). now when i run this script i get this error. /usr/bin/awk: 0403-027 The parameter list is too long. note that the (parameter list is... (9 Replies)
Discussion started by: nullwhat
9 Replies

5. UNIX for Dummies Questions & Answers

Using File Descriptors, traverse a list

I have written this code, and according to my research it SHOULD be going down the list until it is finished, but I am getting blank feedback. Nothing is being output as far as I can tell. #!/bin/sh while echo Enter to start traversing read enter do read list <&3 echo $list done any... (2 Replies)
Discussion started by: MaestroRage
2 Replies

6. UNIX for Advanced & Expert Users

File Descriptors + cron

Hi All, This thread is going to be a discussion basically bringing out more information from the experts on cron jobs and the associated file handles. So, here is the question. There is definitely a constant ' n ' as the maximum number of file handles alloted to a process ' p '. Will... (7 Replies)
Discussion started by: matrixmadhan
7 Replies

7. Programming

Sockets and File descriptors

I am in a Systems programming class this semester, and our current project is to write a program utilizing sockets and fork. For the project, I decided to make my own instant messaging program. I have the code completed, but I have a problem that keeps old clients from communicating with new... (3 Replies)
Discussion started by: gstlouis
3 Replies

8. UNIX for Dummies Questions & Answers

file descriptors

i m trying to learn processes in unix and i've been reading this but i don't quite get it. its regarding file descriptors. : each is a part of file pointers, they point to another area. indexes into an Operating system maintained table called "file descriptor table". one table per process. may... (3 Replies)
Discussion started by: a25khan
3 Replies

9. UNIX for Advanced & Expert Users

File Descriptors

Hello all, A few questions on file descriptors ... scenario : Sun Ultra 30 with Sun OS 5.5.1 , E250 with Solaris 2.6 In one of my servers, the file descriptor status from the soft limit and hard limits are 64 and 1024 respectively for root user. Is the soft limit (64) represents the... (3 Replies)
Discussion started by: shibz
3 Replies

10. Programming

File Descriptors

Hi, I have written a daemon process, to perform certain operations in the background. For this I have to close, the open file descriptors, Does anybody know how to find out the number of open file descriptors ? Thanks in Advance, Sheetal (2 Replies)
Discussion started by: s_chordia
2 Replies
Login or Register to Ask a Question