Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wanted to perform some actions in my Java program whenever a particular interface comes up (network interface ppp0 e.g.). However I figured out it was way too clumsy to keep polling the interface to verify its status.

After finding out if-up.local file in Linux, now I can run a bash script whenever the interface comes up. Works fine, however considering my running Java program, how can I make this script interact with my Java code?

I am considering the following options:

  1. Write a listening socket and from this script send message to this Java socket.
  2. Invoke a C program, and through JNI run my java code.

I am looking for intuitive and less resource intensive approach.

share|improve this question

migrated from Mar 16 '13 at 15:34

This question came from our site for professional and enthusiast programmers.

Probably the simplest way is your first option. Just open a TCP socket and make a request to it from the if-up.local script you found. Using wget/curl for example.

A more complex alternative is to somehow use a netlink socket from java. I think that NETLINK_ROUTE will give you updates on interface creation events, see the first example in that link.

For this second option, either write some JNI or try to find a java library for using unix sockets. In a quick search I've found this one, although I've never used it, so I don't know if it would work for your needs.

A third idea, similar to the first one, instead of a socket, use a FIFO pipe (mkfifo command), you could read it from java as a regular file, and write to it from the bash script with simply a *echo > fifo_file*.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.