Solaris / OpenSolaris This forum is for the discussion of Solaris and OpenSolaris.
General Sun, SunOS and Sparc related questions also go here. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
03-21-2005, 08:30 AM
|
#1
|
|
LQ Newbie
Registered: Mar 2005
Location: Vienna/Austria
Posts: 4
Rep:
|
"ps -ef" using in backquotes
Hi,
I have a question about using the ps within backqoutes (``)
When I tried to write a script which is supposed to run just once at a time
I encountered the following thing which I don't know if it's a BUG or FEATURE.
inside the script 'runonce.sh':
---begin script---
#! /bin/bash
# just run the ps and watch te output
ps -ef | grep 'runonce.sh'
RESULT_FULL=`ps -ef | grep 'runonce.sh'`
echo result_full: "$RESULT_FULL"
---end script---
this script outputs:
[hostnix] ./runonce.sh
oracle 6443 3691 0 15:29:02 pts/8 0:00 /bin/bash ./runonce.sh
result_full: oracle 6462 6443 0 15:29:02 pts/8 0:00 /bin/bash ./runonce.sh
oracle 6443 3691 0 15:29:02 pts/8 0:00 /bin/bash ./runonce.sh
oracle 6464 6462 0 15:29:02 pts/8 0:00 grep runonce.sh
why do I get the /bin/bash ./runonce.sh twice ??
any help welcome
guenter porzer
|
|
|
|
03-21-2005, 08:38 AM
|
#2
|
|
Member
Registered: Dec 2003
Location: Northern VA
Posts: 493
Rep:
|
You're running the ps twice, that's why you're seeing it twice.
|
|
|
|
03-22-2005, 12:54 AM
|
#3
|
|
LQ Newbie
Registered: Mar 2005
Location: Vienna/Austria
Posts: 4
Original Poster
Rep:
|
hi,
actually the ps is not running twice at the same time. It gets started in consecutive.
Besides what I don't understand is why in $RESULT_FULL I'm getting the runonce.sh script twice ?
If I run the same script in KSH( just changing #!/bin/bash to #!/bin/ksh )
I'm geting the expected result of 1 script process and 1 grep process.
As you can see in BASH I'm getting 3 processes 2 scripts running and 1 grep.
thanks
guenter porzer
|
|
|
|
03-22-2005, 01:06 AM
|
#4
|
|
Member
Registered: May 2004
Location: UK
Distribution: Gentoo
Posts: 293
Rep:
|
If you want to know whats happening, add -x to /bin/bash.
Code:
#!/bin/bash -x
#just run the ps and watch te output
ps -ef | grep 'runonce.sh'
RESULT_FULL=`ps -ef | grep 'runonce.sh'`
echo result_full: "$RESULT_FULL"
Useful for debugging.
Last edited by ahh; 03-22-2005 at 01:07 AM.
|
|
|
|
03-22-2005, 12:34 PM
|
#5
|
|
Senior Member
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552
Rep:
|
Are you asking why you see "/bin/bash" and "grep" lines? The grep line is the result of your script. You might try the "grep -v grep" trick or grep for [r]unonce.sh.
|
|
|
|
03-22-2005, 01:16 PM
|
#6
|
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Ubuntu, OL
Posts: 9,311
|
The OP is certainly asking why these two lines appears for a single script:
Code:
oracle 6462 6443 0 15:29:02 pts/8 0:00 /bin/bash ./runonce.sh
oracle 6443 3691 0 15:29:02 pts/8 0:00 /bin/bash ./runonce.sh
My guess would be that bash is either forking or firing a thread that appears to have the same command name as itself (before being updated by the loader possibly).
|
|
|
|
03-23-2005, 03:20 AM
|
#7
|
|
LQ Newbie
Registered: Mar 2005
Location: Vienna/Austria
Posts: 4
Original Poster
Rep:
|
@ jlliagre, you are absolute right.
In the meantime I found a workaround for this behavior.
I just thougt there would be no difference between ksh and bash concerning backquotes ( or at least I've never read anything about this ).
Anyway thanks for all input for this topic !
guenter porzer
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 01:24 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|