/** Posix for Java.
However, sometimes it is necessary to interface with code written for the unix environment - and that code can't be rewritten to use Sockets. In those cases, it would be nice to have simple access to the Posix API without everyone having to reinvent the wheel.
One solution is the posix
package. This package provides
access to the posix API from Java. It uses a JNI library which should
be portable to other posix systems. I started this package with the
intent of making it reusable by others. However, it only has the classes
I have needed for my own projects at present :-). I am making the source
and docs public so that others can reuse what I have so far and so that
I can collect any additions added by others.
There is another posix API for Java used by the Jython project: jnios. I will be looking at incorporating features from that package, or getting rid of my own entirely. I will not get rid of 'posix' if the jnios package requires jython.
The {@link posix.SharedMem} class wraps an ipc shared memory segment. Attaching a SharedMem returns a {@link posix.CPtr} which allows safe and portable access to C format structures in the shared memory. (You can only trash stuff in the share memory, not anywhere else.) Similarly, {@link posix.Malloc} safely allocates and accesses blocks of C memory which can be passed to C apis and are not garbage collected.
/etc/passwd
format. It is a pure Java implementation.
stat.h
and a stat()
method to fill them in. The
{@link posix.File} class extends java.io.File to provide
additional attributes such as lastAccessed().
sigwait()
through JNI to wait on a semaphore. The JNI code actually spawns another
non-Java thread to call sigwait, because that thread must be cancelled
in order to change the set of signals handled by Java.
The Java Signal Thread generates a {@link posix.SignalEvent} for each signal.
This implementation should be portable to any pthreads platform. It uses mutexes and condition variables - which the JVM would also have to use. Currently, there is a small window during which a signal will take the default action when calling Signal.setAction(). Set up your SignalListeners at startup, and there should be no problem.