[PLUG] question on obtaining the PID numbers of a batch command and finding out when a batch script has successfully terminated
Robert Citek
robert.citek at gmail.com
Mon Oct 7 10:53:45 UTC 2024
Sounds like you are wanting to manage parallel jobs. Have you looked into
using the parallel command?
https://www.gnu.org/software/parallel/
Regards,
- Robert
On Sun, Oct 6, 2024 at 8:42 PM American Citizen <website.reader3 at gmail.com>
wrote:
> I had to create this batch file
>
> > gp -q < xaa > xaa.results &
> > echo "$!" | sed "s/^/ps -p /" > x.pid
> > gp -q < xab > xab.results &
> > echo "$!" | sed "s/^/ps -p /" >> x.pid
> > gp -q < xac > xac.results &
> > echo "$!" | sed "s/^/ps -p /" >> x.pid
> > gp -q < xad > xad.results &
> > echo "$!" | sed "s/^/ps -p /" >> x.pid
> > gp -q < xae > xae.results &
> > echo "$!" | sed "s/^/ps -p /" >> x.pid
> > gp -q < xaf > xaf.results &
> > echo "$!" | sed "s/^/ps -p /" >> x.pid
> > sz=1
> > while [ $sz -gt 0 ] ; do
> > sz=`bash x.pid | grep -v "PID TTY" | wc -c`
> > done
> > rm x.pid
> which runs to completion after all the scripts terminated. This is very
> trusting, for example we could get a hang and then get stuck in a
> non-terminating loop.
>
>
> On 10/6/24 19:16, Bill Barry wrote:
> > On Sun, Oct 6, 2024 at 8:25 PM American Citizen
> > <website.reader3 at gmail.com> wrote:
> >> To all:
> >>
> >> I have a simple batch file which has 6 CLI commands to it
> >>
> >> gp -q < xaa > xaa.results &
> >>
> >> gp -q < xab > xab.results &
> >>
> >> gp -q < xac > xac.results &
> >>
> >> gp -q < xad > xad.results &
> >>
> >> gp -q < xae > xae.results &
> >>
> >> gp -q < xaf > xaf.results &
> >>
> >> When I do a simple "% bash do-x.sh" which is the bash script, it runs
> >> normally
> >>
> >> but due to the redirect commands, doing the "ps -fx" will only return
> >> the gp command (along with all live commands the system is running) but
> >> I don't know which xaa, or xab, or xac, etc it is associated with.
> >>
> >> Is there some way to do a "ps -fax | grep gp" command which locates
> >> exactly the pids involved? And can these results be returned as a simple
> >> ascii file, so I can do future inquiries to determine when the program
> >> has stopped running?
> >>
> >> The goal here is to determine when all 6 programs running "gp" have
> >> terminated.
> >>
> >> Randall
> >>
> >>
> > Since bash runs them all 6 commands sequentially you can put one more
> > command at the end that tells you all is finished like
> > echo Finished
> >
> > Bill
>
More information about the PLUG
mailing list