LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bash: how to get the PID of programs started? (https://www.linuxquestions.org/questions/programming-9/bash-how-to-get-the-pid-of-programs-started-181303/)

J_Szucs 05-14-2004 01:27 AM

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).

TheOther1 05-14-2004 08:52 AM

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.

podollb 05-26-2004 09:59 AM

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?

keefaz 05-26-2004 12:56 PM

well try and see ;) do man tcsh also...

podollb 05-26-2004 03:17 PM

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.

gearoid 05-26-2004 04:38 PM

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??

podollb 05-26-2004 05:01 PM

Just a quick note on the listing above that shows some BASH env variables, the second one down has the $ and ! mixed up.

jlliagre 05-26-2004 05:40 PM

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.

TheOther1 05-26-2004 05:58 PM

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.

frandalla 05-26-2004 06:06 PM

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...)

keefaz 05-27-2004 06:45 AM

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


archman78 01-16-2012 02:08 AM

Quote:

Originally Posted by gearoid (Post 955810)
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).


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