Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
#instead of
cat filename | awk 'script'
# use just
awk 'script' filename
# do not put & at the end of the lines, especially after while it will do something "strange" for you
# instead, put only the sysstat commands into background.
awk | while
do
echo
simstat .. &
done
# but take care about the result, that may contain mixed result of the simstat commands.
But globally, since you are also executing this stuff in background, the output of the multiple instances of symstat could be mixed. In your case, (assuming it takes a bit of time) all the echo output could be together, followed by the symstat commands - in any order....
Which part(s) are you trying to send to background? You've got the & after the while, the echo, and the symstat. None of which really make any sense. It might be better to put it all in a script and send the whole script to the background. Or in a function (although I haven't tested if functions could be backgrounded).
You might want the output filename to be driven by the $id2 var, since multi-threading on the same output filename can have many issues. Like the output info being meshed into the file in an unpredictable order. Or the output file being locked and the process having to wait on the previous thread anyway. Plus various risks of so many recursions that you simply don't have enough RAM to keep it all juggling.
You could be wasting effort to, if the symstat program isn't designed to have multiple instances running at the same time. Which you will ultimately have if send one to background and immediately start another. If that program locks file(s), then the 2nd+ instance(s) will have to wait on the previous instance to end anyway. And the 2nd+ instance could prevent the first instance from ending. It's all quite a mess which might be better solved by adding a sleep statement in the loop. sleep 0.3; Not really intuitive, but sometimes the right answer.
shadow_7 - im trying to send the symstat command to background because the symstat itself is a loop
pan64 - yeap, once i remove the & after the while it looks better
jpollard - yeap, single line to send to background is much easier
millgates - works like a charm, perfectly!!!
works perfeclt now, and i cant tail the job to see the progress, its just i dunno why i cant use command "jobs" to check any background jobs - any thought?
However, it works great now, thank you to all that's been helping..cheers guys!!
would be nice to explain what did you try exactly. I can only guess: you wrote a script and inside the script you started several background processes.
The shell you started (which executed your script) is now completed, therefore the current shell has no more jobs to print. The parent process of your background tasks is now 1 (the init process).
would be nice to explain what did you try exactly. I can only guess: you wrote a script and inside the script you started several background processes.
The shell you started (which executed your script) is now completed, therefore the current shell has no more jobs to print. The parent process of your background tasks is now 1 (the init process).
@OP this is likely important because you could end up complaining that things are out of sync or there's some other form of race condition now in your script which you don't understand.
there's a typo earlier - "i CAN tail -f the output, its just i cant see the backgound job by typing jobs ".
the symstat command is to check the I/O reading/write activity for i=5 iteration c=5 count for all the devices in stogrpexport. right now it works fine, its just i cant see any background job id for the loop. again, thanks alot for your help
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.