Page 1 of 1

how to change priority of pipe commands?

Posted: 29 Jun 2012 14:18
by einstein1969
Hi,

I would like to know if there is a possibility of giving a priority to all processes involved in a pipe

Example:


Code: Select all

batch1.cmd | batch2.cmd



I wish that all the children processes involved were assigned the same priority

How can I do?

Re: how to change priority of pipe commands?

Posted: 29 Jun 2012 15:17
by jeb
Hi einstein1969,

I suppose the only way to change the process priority is to use the START cmd.

There are 5 options

Code: Select all

  LOW
  NORMAL
  HIGH
  REALTIME
  ABOVENORMAL
  BELOWNORMAL


So if you want to use it with pipes you could add the start command at each side.

Code: Select all

start "" /b /LOW cmd /c batch1.cmd | start "" /b /LOW cmd /c batch2.cmd


jeb

Re: how to change priority of pipe commands?

Posted: 29 Jun 2012 16:04
by einstein1969
Thanks Jeb,

I have a problem with priority abovenormal, high and realtime.

When i start with belovenormal and low this works. But when i start with higher priority some child processes have "normal" priority

example

Start.cmd:

Code: Select all

@echo off

echo [ZERO] [%time%] > CON

start "" /b /HIGH cmd /c batch1.cmd | start "" /b /HIGH cmd /c batch2.cmd


batch1.cmd:

Code: Select all

@echo off

echo [ONE] [%time%] > CON

start "" /b /HIGH cmd /c batch1_1.cmd | start "" /b /HIGH cmd /c batch1_2.cmd


batch2.cmd:

Code: Select all

@echo off

echo [TWO] [%time%] > CON

:two

set "ln="

set /p "ln="

if defined ln echo [Two] [%time%] %ln%

goto :two


batch1_1.cmd

Code: Select all

@echo off

echo [ONE_ONE] [%time%] > CON

typeperf "\Processore(_Total)\%% Tempo processore"

Rem typeperf "\Processor(_Total)\%% Processor Time"


batch1_2.cmd

Code: Select all

@echo off

echo [ONE_TWO] [%time%] > CON

more +2


When i use LOW and BELOWNORMAL the processes "more" and "typeperf" go LOW or BELOWNORMAL, but when i use priority over NORMAL these keep normal priority :roll:

I use xp sp2.

Re: how to change priority of pipe commands?

Posted: 29 Jun 2012 20:02
by Liviu
jeb wrote:So if you want to use it with pipes you could add the start command at each side.

Interesting thought, thanks for the hint. That said, there is something odd with piping between two "start" commands. The following requires an ^Z to be manually entered before the command completes.

Code: Select all

C:\tmp>start "" /b /LOW cmd /c echo 123 | start "" /b /LOW cmd /c more

123

^Z
C:\tmp>

Liviu

Re: how to change priority of pipe commands?

Posted: 30 Jun 2012 01:36
by Ed Dyreen
'
Some time ago, I discover a bug in the start command of winXP causing priority changes to fail.

Just switching the order of the parameters should do it ( I hope ).

Code: Select all

start "" /high /b "cmd" /c "batch1.cmd" |start "" /high /b "cmd" /c "batch2.cmd"

Re: how to change priority of pipe commands?

Posted: 30 Jun 2012 20:21
by einstein1969
Liviu wrote:
jeb wrote:So if you want to use it with pipes you could add the start command at each side.

Interesting thought, thanks for the hint. That said, there is something odd with piping between two "start" commands. The following requires an ^Z to be manually entered before the command completes.

Code: Select all

C:\tmp>start "" /b /LOW cmd /c echo 123 | start "" /b /LOW cmd /c more

123

^Z
C:\tmp>

Liviu


Yes, odd

It's more problem?

Code: Select all

C:\Documents and Settings\fra>cmd /c more


^D

^A

^X

^B

^Z


C:\Documents and Settings\fra>

Re: how to change priority of pipe commands?

Posted: 30 Jun 2012 20:27
by einstein1969
Ed Dyreen wrote:'
Some time ago, I discover a bug in the start command of winXP causing priority changes to fail.

Just switching the order of the parameters should do it ( I hope ).

Code: Select all

start "" /high /b "cmd" /c "batch1.cmd" |start "" /high /b "cmd" /c "batch2.cmd"


I tried:

Code: Select all

start "" /HIGH /b "cmd" /c "batch1_1.cmd" | start "" /HIGH /b  "cmd" /c "batch1_2.cmd"


but he problem remains :roll:

Re: how to change priority of pipe commands?

Posted: 30 Jun 2012 21:03
by Ed Dyreen
'
Odd, did you verify with taskManager ?, I ran
'test.CMD'

Code: Select all

@echo off

start "" /high /b "cmd" /c "1.cmd" |start "" /high /b "cmd" /c "2.cmd"

pause
exit
'1.CMD' And '2.CMD'

Code: Select all

@echo off

echo.%~n0

pause
and process '2.CMD' runs high as I expected ( did not verify priority of '1.CMD' ) :?

Re: how to change priority of pipe commands?

Posted: 30 Jun 2012 22:18
by Liviu
einstein1969 wrote:It's more problem?

Code: Select all

C:\Documents and Settings\fra>cmd /c more
^D

I don't see the problem there. It works the same with "echo ^D", and the same with just "more" instead of "cmd /c more". The display difference between "^D" (input) and "♦" (output) is just an artifact of how the console I/O works.

The "odd" part in my previous example was the additional ^Z required when piping between "start cmd /c" commands, which is not otherwise necessary when running the commands directly e.g. "echo 123 | more".

Liviu

Re: how to change priority of pipe commands?

Posted: 30 Jun 2012 22:54
by Ed Dyreen
'
Liviu wrote:The "odd" part in my previous example was the additional ^Z required when piping between "start cmd /c" commands, which is not otherwise necessary when running the commands directly e.g. "echo 123 | more".
You are piping into 'start', not into 'more'.

Code: Select all

echo.123 |start "" /b cmd /c more
it is not the same as

Code: Select all

echo.123 |more
yet translates into

Code: Select all

>more
^Z


>echo.123 |start "" /b cmd /c more

123

^Z
>

Re: how to change priority of pipe commands?

Posted: 30 Jun 2012 23:59
by Liviu
Ed Dyreen wrote:You are piping into 'start', not into 'more'.

Right. My first post was in reply to jeb's clever usage of 'start'. The point I was making is that, with piped input, the 'start' behavior does not match the same command being run directly, but (sometimes?) requires an extra ^Z to close the pipe.

In more detail...

Code: Select all

C:\tmp>echo 123 | (cmd /c more)
123


C:\tmp>echo 123 | (start /b cmd /c more)

123

^Z
C:\tmp>
...the first command completes without any additional input, while the second one needs that extra ^Z. The difference is definitely with the receiving end of the pipe i.e. the 'start' part, since running the second line without "/b" opens (as expected) a separate console, and waits for a ^Z to be entered there.

Liviu

Re: how to change priority of pipe commands?

Posted: 01 Jul 2012 12:12
by einstein1969
Ed Dyreen wrote:'
Odd, did you verify with taskManager ?, I ran
'test.CMD'

Code: Select all

@echo off

start "" /high /b "cmd" /c "1.cmd" |start "" /high /b "cmd" /c "2.cmd"

pause
exit
'1.CMD' And '2.CMD'

Code: Select all

@echo off

echo.%~n0

pause
and process '2.CMD' runs high as I expected ( did not verify priority of '1.CMD' ) :?


Your example work. Process 1.cmd run at expected priority.

But if there is other process in 1.cmd or 2.cmd the priority of this process is not respect.

Re: how to change priority of pipe commands?

Posted: 01 Jul 2012 12:22
by einstein1969
Liviu wrote:
Ed Dyreen wrote:You are piping into 'start', not into 'more'.

Right. My first post was in reply to jeb's clever usage of 'start'. The point I was making is that, with piped input, the 'start' behavior does not match the same command being run directly, but (sometimes?) requires an extra ^Z to close the pipe.

In more detail...

Code: Select all

C:\tmp>echo 123 | (cmd /c more)
123


C:\tmp>echo 123 | (start /b cmd /c more)

123

^Z
C:\tmp>
...the first command completes without any additional input, while the second one needs that extra ^Z. The difference is definitely with the receiving end of the pipe i.e. the 'start' part, since running the second line without "/b" opens (as expected) a separate console, and waits for a ^Z to be entered there.

Liviu


may be a problem with the "real" asynchronous start?

Code: Select all

echo 123 | (start /b /wait cmd /c more)

Re: how to change priority of pipe commands?

Posted: 02 Jul 2012 06:14
by einstein1969
And I caught the problem of inverted parameters...

Code: Select all

14.06.02,21> echo 123 | (start /b /wait cmd /c more)
123


14.06.07,43>


exchanging /b /wait

Code: Select all

14.06.07,43> echo 123 | (start /wait /b cmd /c more)

123

^Z
14.07.16,77>


and there is a line...

This in XP SP2