• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

to check and start a process

 
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.
 
author
Posts: 5856
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
 
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.

 
Bartender
Posts: 21000
128
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

 
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
 
The knights of nee want a shrubbery. And a tiny ad:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!