LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.

Notices


Reply
  Search this Thread
Old 03-21-2005, 08:30 AM   #1
porzer
LQ Newbie
 
Registered: Mar 2005
Location: Vienna/Austria
Posts: 4

Rep: Reputation: 0
"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
 
Old 03-21-2005, 08:38 AM   #2
Technoslave
Member
 
Registered: Dec 2003
Location: Northern VA
Posts: 493

Rep: Reputation: 30
You're running the ps twice, that's why you're seeing it twice.
 
Old 03-22-2005, 12:54 AM   #3
porzer
LQ Newbie
 
Registered: Mar 2005
Location: Vienna/Austria
Posts: 4

Original Poster
Rep: Reputation: 0
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
 
Old 03-22-2005, 01:06 AM   #4
ahh
Member
 
Registered: May 2004
Location: UK
Distribution: Gentoo
Posts: 293

Rep: Reputation: 31
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.
 
Old 03-22-2005, 12:34 PM   #5
stickman
Senior Member
 
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552

Rep: Reputation: 53
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.
 
Old 03-22-2005, 01:16 PM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
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).
 
Old 03-23-2005, 03:20 AM   #7
porzer
LQ Newbie
 
Registered: Mar 2005
Location: Vienna/Austria
Posts: 4

Original Poster
Rep: Reputation: 0
@ 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
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
what is "sticky bit mode" , "SUID" , "SGID" augustus123 Linux - General 10 08-03-2012 04:40 AM
Telling people to use "Google," to "RTFM," or "Use the search feature" Ausar General 77 03-21-2010 11:26 AM
"Xlib: extension "XFree86-DRI" missing on display ":0.0"." zaps Linux - Games 9 05-14-2007 03:07 PM
man pages show backquotes as "u" with umlaut? brainclots Red Hat 1 12-01-2003 11:26 PM

LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration