I haven't been following this thread, but instead of C routines, could you make use of the several file-handle related foreigns in the 1!: family?
http://www.jsoftware.com/help/dictionary/dx001.htm 1!:20 y File Numbers and Names. A 2-column table of the open file numbers and names. 1!:21 y Open. Open file named y, creating it if necessary; result is a file number. 1!:22 y Close. Close file named or numbered y. Any locks are released. 1!:30 y Locks. A 3-column integer table of the file number, index, and length of file locks. The argument y is required but ignored. 1!:31 y Lock. y is a 3-element integer vector of the file number, index, and length of the file region to be locked; the result is 1 if the request succeeded, and 0 if it did not. 1!:32 y Unlock. y is a 3-element integer vector of the file number, index, and length of the file region to be unlocked. Example usage: 1!:20 '' NB. List file handles fn0 =. jpath '~temp\a-file-I.have' fh0 =. 1!:21 < fn0 NB. Open file handle 1!:20 '' NB. List file handles +--------+----------------------------------------------+ |60470224|C:\Users\dbron\j64-602-user\temp\a-file-I.have| +--------+----------------------------------------------+ 1!:30 '' NB. List file locks fn1 =. jpath '~temp\another-file-I.have' fh1 =. 1!:21 < fn1 1!:31 fh1,0,1 NB. Lock the first byte of fh1 1 1!:30 '' NB. List file locks 60470272 0 1 1!:32"1 ] 1!:30 '' NB. Unlock all locked files 1 1!:22@>@{."1 ] 1!:20 '' NB. Close all open file handles 1 1 -Dan -----Original Message----- From: programming-boun...@jsoftware.com [mailto:programming-boun...@jsoftware.com] On Behalf Of Raul Miller Sent: Thursday, February 16, 2012 10:18 AM To: Programming forum Subject: Re: [Jprogramming] 2!:1 hangs session in JHS until forked process terminated You could make that into a shared object and load it in J using cd, but if the OS requires hidden files to be open in every process, that could also be a source of problems. I also do not have access to a mac, so I can't tell you what you would need to do there, to run it from under cd. Typically, though, a unix OS has three open file descriptors in a process, and closing them prevents their use but has no other consequences: 0: standard input 1: standard output 2: standard error Closing standard input means you cannot receive any further input Closing standard output means that console messages cease (or that whatever you are writing to -- another file, or whatever) fails. Closing standard error does the same thing for error notifications. Closing these files can cause problems for your code (which is why the usual approach is to reopen these files using /dev/null as the underlying file), but should not hurt the OS. -- Raul On Thu, Feb 16, 2012 at 9:55 AM, Ian Clark <earthspo...@gmail.com> wrote: > Thanks, Raul. > > I can't see how to use your C routine without compiling it and calling > it using 2!:1 (is that what you meant me to do?) It might seriously > corrupt MacOS, which has lots of hidden files open, so I daren't try > it. Anyway, can it be an open child file, if the problem doesn't arise > with jconsole (jcon701) used in place of JHS? > > Now I've at last got my browse tool > http://www.jsoftware.com/jwiki/IanClark/LoBrow working with JHS (by > launching an essential "client" process independently, so as to get > round the 2!:1 hang-up) a lot is coming clear. I think Bill has the > right idea. JHS uses smoutput in an essential way to execute input > sentences, and it can't just be turned off by setting smoutput_z_=: > empty. This impacts on the timer to be used with JHS too, see recent > thread. > > On Thu, Feb 16, 2012 at 1:51 PM, Raul Miller <rauldmil...@gmail.com> wrote: >> I do not know, either, but you can close an already closed file handle, so: >> >> #include <unistd.h> >> >> void closeMostFiles() { >> int f; >> for (f= 0; f < 256; f++) { >> close(f); >> } >> } >> >> If using that routine remedies the symptom you are seeing, it will be >> worth looking at this in more depth. If not, it will probably be a >> different issues. >> >> -- >> Raul >> >> On Tue, Feb 14, 2012 at 6:27 PM, Ian Clark <earthspo...@gmail.com> wrote: >>> I wasn't aware any file handles were inherited. Where do I find them >>> to close? (...Unix rabbit). >>> >>> (The same code works without trouble in j602.) >>> >>> On Tue, Feb 14, 2012 at 9:25 PM, Raul Miller <rauldmil...@gmail.com> wrote: >>>> Have you tried closing the file handles the child process inherits >>>> from the parent? >>>> >>>> -- >>>> Raul >>>> >>>> On Tue, Feb 14, 2012 at 4:04 PM, Ian Clark <earthspo...@gmail.com> wrote: >>>>> 2!:1 is not truly asynchronous in JHS, it seems. The net result is >>>>> that I cannot see how to launch a child process without the session >>>>> hanging until the child terminates. >>>>> >>>>> Strange to say, the jijx session immediately resumes, and will accept >>>>> (re-)input. But it will not execute the inputted expression. Inside a >>>>> verb however, execution continues past 2!:1 (which successfully forks >>>>> the child process), but after completion of the verb the session is >>>>> silent (until the child process is terminated). >>>>> >>>>> Example: >>>>> Suppose test6s.wav is a sound file lasting 6 seconds. (Chosen to last >>>>> long enough to allow "i.6" to be entered.) >>>>> >>>>> 2!:1 'afplay ~/wav/test6s.wav &' >>>>> i.6 >>>>> 0 1 2 3 4 5 >>>>> >>>>> The jijx accepts i.6 but hangs until test6s.wav finishes playing. Only >>>>> then does 0 1 2 3 4 5 appear. >>>>> >>>>> JVERSION >>>>> Engine: j701/2011-01-10/11:25 build: Feb 6 2011 16:16:29 >>>>> Library: 7.01.055 >>>>> Platform: Darwin 64 >>>>> Installer: j701a_mac64.dmg >>>>> ---------------------------------------------------------------------- >>>>> For information about J forums see http://www.jsoftware.com/forums.htm >>>> ---------------------------------------------------------------------- >>>> For information about J forums see http://www.jsoftware.com/forums.htm >>> ---------------------------------------------------------------------- >>> For information about J forums see http://www.jsoftware.com/forums.htm >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm