Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: How to capture system return code when command launched in the background?

by Anonymous Monk
on May 03, 2010 at 09:43 UTC ( [id://838052]=note: print w/replies, xml ) Need Help??


in reply to Re: How to capture system return code when command launched in the background?
in thread How to capture system return code when command launched in the background?

The Java program is a daemon process that I need to launch, runs continuously in the background listening to a JMS queue and writhing out XML messages. The Perl program scans the directory for XML files (messages from the JMS client written out) and reads them in. When the Perl program is launched, it needs to check if the JMS daemon is running and if not start it.

I am going to implement a small sleep after the system call, then recheck if the process is running. If not exit with an error.

Thanks Everyone for the helpful replies.

  • Comment on Re^2: How to capture system return code when command launched in the background?

Replies are listed 'Best First'.
Re^3: How to capture system return code when command launched in the background?
by afoken (Chancellor) on May 03, 2010 at 14:53 UTC

    I think that djb's daemontools could really help you here. Let daemontools handle the java process. The daemontools will take care of starting and restarting the java process, and they will also take care of reliable logging and safe log rotation. Daemontools have a reliable way to find out if a daemon is running or not (svok for programs, svstat for humans). Daemontools have a reliable way of controlling a daemon (svc). So all you need to do is to invoke svok and perhaps svc. You don't even have to check if the daemon is already running, svc -u /service/java-daemon does nothing if the java daemon is already running.

    You could also consider using the inotify / dnotify API instead of scanning for files, and have your Perl script wait for any output of the java process. Your perl script could perhaps also run as a daemon under control of daemontools. You would get automatic restarts and logging for free ...

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://838052]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2024-04-19 07:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found