Page 1 of 1

Multiple batch jobs calling the same batch file causing halt

Posted: 14 Dec 2009 21:41
by rayc
I have a client that runs many .BAT files overnight. However, I noticed that most of the files call some common .BAT files. My question is this: What happens when two BAT files call the same (secondary) BAT file at the same time? Does this cause any freezing.

I ask because we get some support calls from time to time from the operator who executes these BAT files at 4am. Sometimes, it works fine, but sometimes he tells us that he has to kill a job and rerun them because some batch files take too long.

Most of the files just take seconds to execute. So I am asking myself what could be the problem. Any suggestions?

Note that some files perform CALLs to other BAT files that are also called from other BAT files. One of the files in the chain ends with an EXIT as well.

Posted: 16 Dec 2009 11:01
by avery_larry
Not nearly enough information. It depends entirely on what the batch files do. There's no problem in general -- but if they're trying to write to the same file (for instance) then you'll get problems.

Posted: 17 Dec 2009 21:43
by rayc
What types of problems might occur if they write to the same file. All of them write to a central log.log file at the end of their execution. When you say "then you'll get problems", what do you mean? Is it possible that they might freeze? I'm not sure how batch files react to this sort of problem.

Posted: 18 Dec 2009 15:45
by avery_larry
Well, dos isn't "smart" enough to properly allow a file to be written to *at the same time* by multiple programs or whatever. So if 2 different scripts are trying to write to the same file *at the exact same moment*, then the results will, pretty much by definition, be unpredictable.

So in other words, I have no idea what would happen in that situation. I can say that I've had multiple batch files (running on 1 machine) writing to the same log file and I've never had problems -- but it's only about 20 lines written to in the log file total and I always assume that I've never had a "collision".

If it was me, I'd start re-writing all those batch files to include error checking. You could even use that central log file to allow each one to keep track of where the other batch files are in their progress (in case you need to have 1 batch file finish before another one starts).

Posted: 20 Dec 2009 00:40
by rayc
I was informed by my client that there is a software called Control-M that actually runs the batch files in the middle of the night. This tool occasionally reports that one batch file is taking too long and must be killed. When I looked at the batch file and ran it in the development environment, the actual time takes about 10 seconds for the batch file to execute. So I ask myself why Control-M (sometimes) reports that the batch file surpassed the 30 minute limit that was set for it.

I did notice one thing. One of the called batch files has an EXIT command in it at the end (last line). Once this EXIT command is executed, the control must return to the calling batch file. Is the EXIT command a reliable one? Can that cause the main (calling) batch file to wait indefinitely?

Posted: 20 Dec 2009 04:40
by !k
rayc wrote:One of the called batch files has an EXIT command in it at the end (last line). Once this EXIT command is executed, the control must return to the calling batch file.


It seems this is the problem. Need to use EXIT /B. At the end of the file, you can use nothing.

Posted: 20 Dec 2009 11:43
by rayc
So if I remove the EXIT, this will not affect any of the other batch files? It is the last line anyways. What does the/B mean?

Posted: 20 Dec 2009 14:10
by !k
rayc wrote:So if I remove the EXIT, this will not affect any of the other batch files?
Last line "EXIT" will not be affected
rayc wrote:What does the/B mean?
EXIT /B when used within a batch, exits the script without closing the calling batch.
You must also use the CALL command to invoke other batchs.

Re: Multiple batch jobs calling the same batch file causing

Posted: 28 Nov 2013 00:02
by shayanjameel08
Hi i am seeking for a technician opportinity with coatings experience. I am Small Batch Technician and responsible for producing products..!