[PLUG] question on obtaining the PID numbers of a batch command and finding out when a batch script has successfully terminated
American Citizen
website.reader3 at gmail.com
Tue Oct 8 00:16:51 UTC 2024
Thanks to all who answered.
Ben's solution was most intriguing to me. I actually had a bash script
built from the pid as each started up, then simply parsed the bash
script (with a delay of course) until no more pids in the list were
executing.
I am not sure that a wait command would work for me because I had each
process kicked off to execute in the background.
- Randall
On 10/7/24 10:54, Ben Koenig wrote:
> You may want to create a launcher function for your calls to gp, and then capture the return value with $?. So something like this:
>
> PROC_LIST="xaa xab xac xad xae xaf"
> function foo () {
> gp -q < $1 > $1.results
> echo "$1 finished: $?" >> process_log.txt
> }
> for X in $PROC_LIST; do
> foo $X
> done
>
> In the above example, when gp exits the return value is captured and appended to process_log.txt. By parameterizing your calls to 'gp' you can add logging or pid tracking functionality specific to that one call. You can even create temporary pid files for each one that you can then monitor externally.
>
> Adjusting this to use parallel would probably give you a more robust solution.
>
> -Ben
>
>
> On Sunday, October 6th, 2024 at 6:24 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
More information about the PLUG
mailing list