• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

to check and start a process

 
raj esh
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot.
i understand the script . i will try to do this in bash shell.

 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

 
anish patil
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use pgrep see man pages for it
while using the ps use -w option ==> ps -aefww | grep tomat
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic