carlos-montiers / enhancedbatch

Enhances your windows command prompt https://www.enhancedbatch.com
Other
5 stars 1 forks source link

Saving PID of newly started cmd.exe instance into a variable #11

Closed lazna closed 4 years ago

lazna commented 4 years ago

I have used http://www.scheibli.com/projects/getpids/ for some time many years a go, but trying it now, does not working (print PIDs to screen and remain open until CTRL+C), tested on Windows 7 and 10. Maybe some windows update change something.

Now if need to identify batch started by other batch, putting my own process numbers into a TITLE and than filter running processes by TASKLIST, but this is cumbersome.

adoxa commented 4 years ago

Getting the current pid is trivial, but how is it useful? I'm not sure what you actually want.

lazna commented 4 years ago

Have monitoring batch program which reading list of devices from database every 5 minutes and start hundreds instances of another batches which perform monitoring task (each batch on each device), write its results and terminate. Time by time some batch hangs for some reason, do not terminate and stay in memory. There is another batch which is periodically started just before another period, and perform TASKKILL on all cmd.exe except its own PID (taskkill /FI "pid ne 12345" /F)

Sometimes I perform kind of "paralellism" to make task runtime shorter. In beginning of batch some task (which no more interact with parent bach) is started, but parent batch in some moment need to know if child batch already terminate (or wait till child terminate). This is easily done if PID of child batch is known.

There are number of another usecases deep in my batch history, but cant find it now in my archive now. But its true I am using batch files by many "non-standard" ways ;-)

BTW: Using http://www.pirosa.co.uk/demo/wxargs/wxargs.html to limit number of processes running simultaneously (by the number of CPU cores), which should be another cool feature for EB....

adoxa commented 4 years ago

Getting our own PID isn't a problem, but getting a child PID might be. Carlos floated the idea of asynchronous batch processing in an email, sounds like what you want.

carlos-montiers commented 4 years ago

With the PIPE extension seems that this will become possible