Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have four bat files and a four core machine. Is it possible to assign each run to each core i.e. 1 job for 1 core. Is there any way to control this with commands?

share|improve this question
    
What could you be doing in a batch file that is not IO bound? If the processes you are trying to run are IO bound, then trying to balance them via processor affinity is not going to accomplish very much. Try providing more specifics about the process and what it does and you might get some much more appropriate comments for your situation. –  dmarietta Dec 6 '13 at 16:08

2 Answers 2

On Windows 7 and above, you can use START /AFFINITY to launch a process and restrict it to a one or more specific processors.

For earlier versions of Windows (XP and beyond), you can download the free Microsoft utility PsExec v2.0 that not only allows you to assign a process to specific processor(s), it also allows you to run a process on a remote machine.

In your comment to Chopper3's answer, you say you have a queue of many jobs, and you want to fire off one job for each processor, and then have the remaining jobs wait until a processor is free. At Parallel execution of shell processes on StackOverflow I posted a sample batch file that does pretty much what you want. As written, it sets up a queue of jobs and then limits the number of concurrent processes. It assumes the OS will handle load balancing accross the available processors. Even better, the script is designed to also support PsExec, so you should be able to assign each process to a remote machine and/or specific processor(s). However, I have not tested the PsExec functionality.

share|improve this answer

If you use the start /b whatever.bat it will start the batch file in the background, if you do this at once then the kernel will schedule the jobs accordingly - you can't, and wouldn't want to, assign a core per batch file - you just want them running asynchronously and for the OS to manage the workload.

share|improve this answer
    
I have huge runs. Say I have 6 jobs. I would want to assign 4 of them at once to the four cores and remaining ones to be fired once the earlier four are finished. Is there no way at all to specify the core for each job? –  user741592 Aug 6 '13 at 10:10
1  
You can't specify this as part of the process start no, as per my answer. But you can do this after the process is running by opening Task Manager and right clicking on the process then choose Set Affinity and pick a logical core. Oh and just use the CALL function at the end of each process to start the next one sequentially. –  Chopper3 Aug 6 '13 at 10:16
    
I just noticed that start/affinity does help. –  user741592 Aug 6 '13 at 10:22
    
You can assign a job to a specific processor using START /AFFINITY or PsExec -a. Whether or not you should could be debated. See my answer –  dbenham Dec 6 '13 at 15:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.