LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 05-30-2007, 08:40 PM   #1
fj8283888
LQ Newbie
 
Registered: Mar 2007
Posts: 15

Rep: Reputation: 0
kill specific process


Hi,

I put the script into .bash_profile which runs a process when uses login to that account, the problem is when login again, the process will run again and cause the crash, how could I put the condition to check whether the process has been run, if it is run, no need to call it.

that what I found in process

root 14062 14061 0 09:23 ? 00:00:00 ./testsrv lt.cf3

thx heaps
 
Old 05-30-2007, 11:01 PM   #2
SlackDaemon
Member
 
Registered: Mar 2006
Distribution: RedHat, Slackware, Experimenting with FreeBSD
Posts: 222

Rep: Reputation: 30
You would use an 'if'statement to check the $? variable. If the last command was successful you will receive a value of 0. If you want specifics on what to do, you'll have to provide more information.
 
Old 05-30-2007, 11:42 PM   #3
fj8283888
LQ Newbie
 
Registered: Mar 2007
Posts: 15

Original Poster
Rep: Reputation: 0
First, thx for your reply.

in the .bash_profile
I delcare as:

Code:
./testsrv test.cf 2>e2.log

could you I put the if condition there to check whether this process has been called or not

Thx heaps
 
Old 05-31-2007, 12:45 AM   #4
SlackDaemon
Member
 
Registered: Mar 2006
Distribution: RedHat, Slackware, Experimenting with FreeBSD
Posts: 222

Rep: Reputation: 30
Use pgrep and the name of the process you are checking. Then test $? to see if the value is 0.

example:

pgrep processName
if [ $? == 0 ]; then
# code to execute when process is already running
else
#code to execute when process is not running
fi
 
Old 05-31-2007, 04:14 AM   #5
fj8283888
LQ Newbie
 
Registered: Mar 2007
Posts: 15

Original Poster
Rep: Reputation: 0
thx heaps, I get it
 
Old 05-31-2007, 04:54 AM   #6
fj8283888
LQ Newbie
 
Registered: Mar 2007
Posts: 15

Original Poster
Rep: Reputation: 0
I wrote the script as

Code:
if [ $a =="0"];then
echo "a"
else
echo "b"
fi
what's the error of it?
line 21: syntax error near unexpected token `else'
-bash: /usr/mrv2/.bash_profile: line 21: `else'
 
Old 05-31-2007, 06:28 AM   #7
SlackDaemon
Member
 
Registered: Mar 2006
Distribution: RedHat, Slackware, Experimenting with FreeBSD
Posts: 222

Rep: Reputation: 30
Quote:
Originally Posted by fj8283888
I wrote the script as

Code:
if [ $a =="0"];then
echo "a"
else
echo "b"
fi
what's the error of it?
line 21: syntax error near unexpected token `else'
-bash: /usr/mrv2/.bash_profile: line 21: `else'
That worked on my system but after I put a space between "0" and ]
also place a space between ]; and then
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Kill specific Wine program from Command Line Brian114 Linux - Software 4 06-07-2011 04:02 AM
how to kill specific python script melinda_sayang Linux - General 2 12-04-2005 03:31 AM
cannot kill process (kill -9 does not work) mazer13a Linux - General 1 05-27-2005 02:32 PM
kill a specific session in windows rabeea General 8 12-15-2004 03:10 PM
How to kill a certain process? AMDPwred Linux - General 3 10-01-2002 01:40 PM


All times are GMT -5. The time now is 08:21 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration