LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-14-2004, 01:27 AM   #1
J_Szucs
Senior Member
 
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Rep: Reputation: 58
Bash: how to get the PID of programs started?


I start a program from a script like this:
for line in `streamripper http://somesite.com/`; do
...
done

How could the script determine what is the PID of the streamripper process started? (There may be several streamripper processes already running.)

I want to continuously monitor how the streamripper process proceeds. Streamripper outputs the necessary information periodically on the screen, but its output lines end with a CR character (so it puts everything on one line on the screen).

How could the script cycle through these lines ending with CR?

Is it possible to do this realtime? I mean the script should process each line immediately when it gets a line ended with the CR line delimiter, and it should not wait until it gets an LF line delimiter (the latter would cause several minutes of delay, and false operation).
 
Old 05-14-2004, 08:52 AM   #2
TheOther1
Member
 
Registered: Feb 2003
Location: Atlanta, GA
Distribution: RHAS 2.1, RHEL3, RHEL4, SLES 8.3, SLES 9, SLES9_64, SuSE 9.3 Pro, Ubuntu, Gentoo
Posts: 335

Rep: Reputation: 32
BASH Variables:
$$ = current pid
!$ = last command issued
$? = error code of last command
$0 = command
$1 = argument #1, also $2,$3,$4, etc.
@ = full command line
$_ = current shell

I would fire up streamripper and pipe output to a script (Perl preferably) and stdout using tee. Yes it can be done.
 
Old 05-26-2004, 09:59 AM   #3
podollb
Member
 
Registered: Oct 2003
Location: Grand Forks, ND
Distribution: Suse/Slackware/RH
Posts: 161

Rep: Reputation: 30
What about TCSH?

Does anyoen know if those BASH variables described above hold true for TCSH? And if not how would I go about getting the PID of a process I start in a TCSH script?
 
Old 05-26-2004, 12:56 PM   #4
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
well try and see do man tcsh also...
 
Old 05-26-2004, 03:17 PM   #5
podollb
Member
 
Registered: Oct 2003
Location: Grand Forks, ND
Distribution: Suse/Slackware/RH
Posts: 161

Rep: Reputation: 30
Nothing in man tcsh (I looked there first) and I tried to use them but wasn't sure if I was even doing it right.
 
Old 05-26-2004, 04:38 PM   #6
gearoid
Member
 
Registered: Nov 2003
Location: Ireland
Distribution: Red Hat 9
Posts: 49

Rep: Reputation: 15
sorry to break from the point here but something you hit on other1....

I am reading a tutorial on bash scripting at the moment and am coming across all sorts of bash variables like while [ $# -gt 1 ]; do and if file $ff. What do the $#, the $ff, the -gt 1 and so on mean here? And is there any place I can go to see a good listing of all these bash variables??
 
Old 05-26-2004, 05:01 PM   #7
podollb
Member
 
Registered: Oct 2003
Location: Grand Forks, ND
Distribution: Suse/Slackware/RH
Posts: 161

Rep: Reputation: 30
Just a quick note on the listing above that shows some BASH env variables, the second one down has the $ and ! mixed up.
 
Old 05-26-2004, 05:40 PM   #8
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
two more corrections:
- the last one is only meaning the current shell at startup, then means the last argument of the previous command.
- the one before (@) is missing a $ prefix.
 
Old 05-26-2004, 05:58 PM   #9
TheOther1
Member
 
Registered: Feb 2003
Location: Atlanta, GA
Distribution: RHAS 2.1, RHEL3, RHEL4, SLES 8.3, SLES 9, SLES9_64, SuSE 9.3 Pro, Ubuntu, Gentoo
Posts: 335

Rep: Reputation: 32
Yea, OK I screwed up. So my post was worth exactly what you paid for it!

try these references:

Bash Reference PDF or Linux in a nutshell or linux-bash or Bash HOW-TO or Advanced Bash Scripting Guide or Linux Scripting Tutorial or Google it.
 
Old 05-26-2004, 06:06 PM   #10
frandalla
Member
 
Registered: Oct 2003
Location: Tokyo - Japan
Distribution: Slackware
Posts: 348
Blog Entries: 1

Rep: Reputation: 37
hey, on linux there's a program called pidof
you use it like this: pidof xmms
and it will return you the program pid.
ex.:
#echo `pidof init`
1

*EDIT* (I guess I saw this on Debian... I was so sure it was a standard piece of software I posted this here without even trying it on my box - I'm using slack. I'll try to find out about it...)

Last edited by frandalla; 05-26-2004 at 06:08 PM.
 
Old 05-27-2004, 06:45 AM   #11
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Quote:
Originally posted by podollb
Nothing in man tcsh (I looked there first) and I tried to use them but wasn't sure if I was even doing it right.
Code:
 man tcsh | grep process
       $$      Substitutes  the  (decimal)  process number of the
       $!      Substitutes the (decimal) process  number  of  the
               last  background  process  started  by this shell.
       If this is a terminal and if the process attempts to  read
       from  the  terminal,  then  the process will block and the
       was job number 1 and had one  (top-level)  process,  whose
       process id was 1234...
        ... and much more
 
Old 01-16-2012, 02:08 AM   #12
archman78
LQ Newbie
 
Registered: Jan 2012
Posts: 1

Rep: Reputation: Disabled
Quote:
Originally Posted by gearoid View Post
sorry to break from the point here but something you hit on other1....

I am reading a tutorial on bash scripting at the moment and am coming across all sorts of bash variables like while [ $# -gt 1 ]; do and if file $ff. What do the $#, the $ff, the -gt 1 and so on mean here? And is there any place I can go to see a good listing of all these bash variables??
while [ $# -gt 1 ]; do...;done

This is a bash loop that reads "While the number of supplied arguments is greater than 1, do the following code and repeat". Not sure that $ff means anything in bash (unless you specified a $ff variable).
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
no pid file in /var/run for programs wolfe2554 Linux - Software 5 01-01-2007 12:02 AM
get pid in bash merlin23 Linux - Newbie 3 12-07-2004 08:38 AM
Is there an easy way to get debian started with programs like mandrake installs? r3dhatter Debian 23 10-22-2004 12:20 AM
bash script, monitoring running PID? thebover Programming 4 08-26-2004 02:42 PM
small bash script to kill a PID flosch Linux - General 3 05-06-2004 09:28 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:28 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