ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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).
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.
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?
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??
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
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.
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...)
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
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).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.