It's not a secret anymore!*
The moose likes Linux / UNIX and the fly likes to check and start a process Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "to check and start a process" Watch "to check and start a process" New topic
Author

to check and start a process

raj esh
Greenhorn

Joined: Apr 03, 2010
Posts: 10
i am new to unix. please give the script
my script need to check a process running or not and if process is not running, script has to start that process.
assuming process as simple java program.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5812
    
    7

You can use the ps command to see what is running. To check for Java apps, use:

ps -ef | grep java

Alternately, you could use the jps app that comes with the JDK - it lists the Java processes running and gives the main class name.

AS far as a full script goes, you are on your own,: NotACodeMill


JBoss In Action
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
I would be careful when you "grep" for just for java. It may return other processes that use java.

Also when you execute the command 'grep java'. The actual command 'grep java' will show up in the process status queue.

One suggestion is to grep for the script that will execute the java program. This will only work if the script blocks while the java program program is running.

For example:
java_program_script.ksh:




This is just one example.
raj esh
Greenhorn

Joined: Apr 03, 2010
Posts: 10
thanks a lot.
i understand the script . i will try to do this in bash shell.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15957
    
  19



Customer surveys are for companies who didn't pay proper attention to begin with.
anish patil
Greenhorn

Joined: May 02, 2010
Posts: 10
use pgrep see man pages for it
while using the ps use -w option ==> ps -aefww | grep tomat
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: to check and start a process
 
Similar Threads
restarting script
Check the Cluster status before start the cluster using WLST
firebug is not breaking on breakpoints
Tomcat not running
WAS4.0 on XP