This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: kawa shell concept
* Jamison Hope [2012-02-07 22:01] writes:
> On Feb 7, 2012, at 4:19 PM, Helmut Eller wrote:
>
>> * Per Bothner [2012-02-07 19:18] writes:
>>
>>>>> Pipe
>>>>>
>>>>> (run in: (run "command1") "command2")
>>>>
>>>> How's this implemented in Java? Is there even a JDK API to create
>>>> real
>>>> pipes?
>>>
>>> The default (and initial) implementation would just use a helper
>>> thread.
>>> It reads from the output stream of command1, and writes to the input
>>> stream of command2. Do you know of any problems (like risk of
>>> deadlock)
>>> doing it this way?
>>
>> No; it just sounds inefficient.
>
> It wouldn't be that hard to call through to pipe(2), especially with
> JNA.
> The tricky part is that then we'd have to have a way to get the file
> descriptor ints used by pipe() to be used by the
> InputStream/OutputStream
> of the child Process with calls to read(2) and write(2). That seems like
> it would imply a custom InputStream subclass, which would imply a custom
> Process subclass to return our special InputStream, which would imply
> not
> using the Process subtype returned by Runtime.exec() or
> ProcessBuilder.start().
> So, we'd probably have to use JNI to call fork/exec or pthread_spawn().
> Doesn't really seem worth it.
A problem is that fork only forks the thread that called it. For a JVM
that often means that the GC doesn't work properly in the child process.
It's probably easier/necessary to write such things in C/C++ directly
which doesn't depend on other threads.
Helmut