how to change priority of pipe commands?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
einstein1969
Expert
Posts: 941
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

how to change priority of pipe commands?

#1 Post by einstein1969 » 29 Jun 2012 14:18

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?
Last edited by einstein1969 on 29 Jun 2012 15:23, edited 1 time in total.

jeb
Expert
Posts: 1041
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: how to change priority of pipe commands?

#2 Post by jeb » 29 Jun 2012 15:17

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

einstein1969
Expert
Posts: 941
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: how to change priority of pipe commands?

#3 Post by einstein1969 » 29 Jun 2012 16:04

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.

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: how to change priority of pipe commands?

#4 Post by Liviu » 29 Jun 2012 20:02

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

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: how to change priority of pipe commands?

#5 Post by Ed Dyreen » 30 Jun 2012 01:36

'
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"

einstein1969
Expert
Posts: 941
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: how to change priority of pipe commands?

#6 Post by einstein1969 » 30 Jun 2012 20:21

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>
Last edited by einstein1969 on 30 Jun 2012 20:41, edited 1 time in total.

einstein1969
Expert
Posts: 941
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: how to change priority of pipe commands?

#7 Post by einstein1969 » 30 Jun 2012 20:27

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:

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: how to change priority of pipe commands?

#8 Post by Ed Dyreen » 30 Jun 2012 21:03

'
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' ) :?

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: how to change priority of pipe commands?

#9 Post by Liviu » 30 Jun 2012 22:18

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

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: how to change priority of pipe commands?

#10 Post by Ed Dyreen » 30 Jun 2012 22:54

'
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
>

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: how to change priority of pipe commands?

#11 Post by Liviu » 30 Jun 2012 23:59

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

einstein1969
Expert
Posts: 941
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: how to change priority of pipe commands?

#12 Post by einstein1969 » 01 Jul 2012 12:12

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.

einstein1969
Expert
Posts: 941
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: how to change priority of pipe commands?

#13 Post by einstein1969 » 01 Jul 2012 12:22

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)

einstein1969
Expert
Posts: 941
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: how to change priority of pipe commands?

#14 Post by einstein1969 » 02 Jul 2012 06:14

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

Post Reply