How do I find the current machine’s full hostname in C (hostname and domain information)?

To get a fully qualified name for a machine, we must first get the local hostname, and then lookup the canonical name. The easiest way to do this is by first getting the local hostname using uname() or gethostname() and then performing a lookup with gethostbyname() and looking at the h_name member of the struct … Read more

Linux/POSIX equivalent for Win32’s CreateEvent, SetEvent, WaitForSingleObject

The POSIX equivalent for what you described is POSIX condition variables. Note that condition variable must always be used in pair with a POSIX mutex, but quite frequently several condition variables use the same mutex, so if you aren’t going to use the mutex exclusively for the condition variable, you shouldn’t place it in the … Read more

Is there a Java library of Unix functions?

I’m aware of two compelling projects: posix for Java (based on JNI) [derived from Jython] jna-posix (based on JNA) [derived from JRuby] Personally I like very much JNA. Take a look at this example of mine, mapping link(2): import com.sun.jna.Library; import com.sun.jna.Native; class Link { private static final C c = (C) Native.loadLibrary(“c”, C.class); private … Read more

Recursive mkdir() system call on Unix

There is not a system call to do it for you, unfortunately. I’m guessing that’s because there isn’t a way to have really well-defined semantics for what should happen in error cases. Should it leave the directories that have already been created? Delete them? What if the deletions fail? And so on… It is pretty … Read more