Know when a particular application is running


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Know when a particular application is running
# 1  
Old 10-02-2010
Know when a particular application is running

Is it possible in unix to write a script that could determine when a particular application is running or not ?
# 2  
Old 10-02-2010
There are several ways. It would be useful in the future if you mentioned your OS.
here are two ways:

Code:
#On systems with pgrep - like Solaris Linux
is_running() 
{
   pgrep $1
}
# almost any system
is_running()
{
   ps -ef | grep "$1"  | grep -v "grep"
}

usage
Code:
is_up=$(is_running myppname)
if [[ -z "$is_up" ]] ; then
    echo "myappname is not running"
else
    echo "myappname is running"
fi

# 3  
Old 10-02-2010
Thanks Jim

Its an old version of HP unix, I'll give your second iteration a try.
# 4  
Old 10-03-2010
In addition to Jim's suggestion, you could kill the output inside the function and then I think it looks nicer when you use it:
Code:
is_running()
{
   pgrep "$1" >dev/null 2>&1
}

or
Code:
is_running()
{
   ps -ef | grep "$1" | grep -qv grep
}

Then you can do this:
Code:
if is_running myppname
then
    echo "myappname is not running"
else
    echo "myappname is running"
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash pauses while application running

I want a really easy thing to happen, I want the bash to open a picture with QuickPictureViewer (qpv) and then some seconds or after a if function with some specific value that this process is terminated. The problem is, that the bash opens the picture and the script doesn´t go on (because the... (2 Replies)
Discussion started by: SasuGamer
2 Replies

2. UNIX for Beginners Questions & Answers

Application server is running or not

Hi All, i am trying to find whether nginx is installed or not as well process is running or not on my centos server. For that i am searching for the nginx configuration file nginx.conf based on that i am printing the ouput. Below script i am using. var=$(find / -name "nginx.conf" !... (1 Reply)
Discussion started by: balu1234
1 Replies

3. Shell Programming and Scripting

How to interrupt running application?

Hello i have problem passing ctrl+C into shell script this script will run application and return value but never ends and stay running. i tried trap and not working at all the command should look like this : sarm pcsp -s CHG_M_P1 i want something to stop this command after... (9 Replies)
Discussion started by: mogabr
9 Replies

4. UNIX for Dummies Questions & Answers

How to start application and keep script running

What I'm looking for is best explained with a little example. #!/bin/bash gedit echo "I need this message to appear while gedit is still running, but it appears only then when I close gedit." Of course most of the times you want the script to wait, but in this case I want to start a new... (5 Replies)
Discussion started by: MrZehl
5 Replies

5. UNIX and Linux Applications

Exceptions while running application on headless linux

I want to install executable file(Demo.bin) on vMA4.0 virtual machine using ssh. Same can be installed on all other Linux/Unix box. but when I am trying to run it on vMA,I am getting the following error-- Could you please advise me how to approch this problem and how to resolve it? (4 Replies)
Discussion started by: smartgupta
4 Replies

6. Shell Programming and Scripting

To access UNIX server from Tk application running on Windows

Hi, I am new to this forum and this is my first post. I want to know that if I make an application in Tk (version of Tcl to create GUI) in windows and want to run to UNIX server, is it possible ? In other words, can I access a UNIX server through a Tk application running on windows ? ... (1 Reply)
Discussion started by: ratneshnagori
1 Replies

7. Solaris

How to find an application running on multithread?

Dear Friends, We have one T5240 server with 128vcpus in our lab.Performance of the server is very poor. Application uses only 2% of processor..I heard that single thread application performs slowly in coolthread.How can we find whether the application running on multithread or single thread? If... (7 Replies)
Discussion started by: nicktrix
7 Replies

8. Shell Programming and Scripting

command to know the application running of the port

Hi, is there any command to findout that which application is using the particular port. or whether any port is occupied with the specfic process id ? (4 Replies)
Discussion started by: mail2sant
4 Replies

9. Shell Programming and Scripting

Query on sending inputs to a running application

Hi I need a help for below : I am running an application XXXX , and when it starts i am passing a file name called "connect.spb" and after the application connects to the server i am sending filename "accept.spb" as a parameter. DL385:$ ./XXXX This is XXXX (Reproducer by Order or RelaY) ... (1 Reply)
Discussion started by: srkelect
1 Replies

10. UNIX for Dummies Questions & Answers

Script to Test Application Server is running

Hi, I'm a complete novice at Unix and need to create a script that does the following... checks to see if an application server is running. If the app is running then print 'Available' Else print 'Unavaliable' exit from scriopt I have no idea where to start. I'd be very grateful... (0 Replies)
Discussion started by: duglover
0 Replies
Login or Register to Ask a Question