0

I have a Java daemon which run as a normal daemon. I want to pass commands from the shell like the a regular unix program. Can you give me some information how I can do this?

P.S For example:

I want with this command to restart the Java daemon:

$javaDaemon -restart 

or list memory

$javaDaemon -m
Torben
  • 3,805
  • 26
  • 31
Peter Penzov
  • 1,126
  • 134
  • 430
  • 808
  • Do you want to interact with the running program? (What is a regular UNIX program?) –  Oct 02 '13 at 12:05
  • Yes, tell me every option that you can think of. – Peter Penzov Oct 02 '13 at 12:07
  • What options do you already know? Please describe what you have tried. –  Oct 02 '13 at 12:08
  • I use shell script which passes the commands and the arguments from the shell to the daemon. But I would like to use pure Java code for this because I want to use the daemon on Windows and Linux and this makes the things more complicated. – Peter Penzov Oct 02 '13 at 12:35
  • I don't understand. How, in your opinion, are commands passed to a daemon in a "regular" unix program? Please describe your use case in more detail. Please edit your question for this. –  Oct 02 '13 at 12:38
  • Post updated with commands examples. – Peter Penzov Oct 02 '13 at 12:42
  • Take a look at http://stackoverflow.com/questions/7687159/how-to-convert-a-java-program-to-daemon-with-jsvc –  Oct 02 '13 at 12:48

1 Answers1

4

Your daemon program and the program that gives commands (commander) to the daemon must have a common resource between them.

For example the shared resource could be a file. The commander writes commands to a file and the daemon polls the file regularly for changes. When daemon detects changes it reads the file and executes the commands. You must implement file locking so that the daemon and commander do not try to access the file at the same time.

The shared resource could also be a socket. Your daemon opens and listens to a socket and the commander writes commands to it directly.

There are other options too. You should research "common inter process communication" using a search engine like Google.

Torben
  • 3,805
  • 26
  • 31