D
dmedhora
Hi,
I want to read commands from a file and execute 5 of them
simultaneously. Then if any command(s) finish running, I
want to continue reading from the file and executing the
commands such that at any 1 time, there are always, say, 5
processes running.
This script however should be able to have multiple instances
of it running as well, so for example a usage of:
myscript 1 5
and an input file containing:
1 sleep 40
1 sleep 45
1 sleep 32
1 sleep 34
1 sleep 34
1 sleep 34
1 sleep 34
1 sleep 34
1 sleep 34
1 sleep 34
1 sleep 34
1 sleep 34
1 sleep 34
1 sleep 34
1 sleep 34
1 sleep 40
etc..
should execute the first 5 sleeps then if 2 sleeps finish I
should be able to read and execute 3 more...etc
I can do this successfully if my logic greps for sleep and
I just call the script once. But,
I should *also* be able to fire off
myscript 2 5 (run commands beginning with 2, keeping 5 running)
and
myscript 4 4 (run commands beginning with 4, keeping 4 running)
here myscript 2 5 would read in from file as below, say,
2 sleep 34
2 sleep 32
2 sleep 99
2 sleep 80
2 sleep 70
2 sleep 50
2 sleep 80
2 sleep 30
2 sleep 80
2 sleep 40
2 sleep 10
2 sleep 81
2 sleep 20
etc
so if I simultaneously run
myscript 1 5
myscript 2 5
then I cannot depend on grep sleep *and* keep the counts proper.
If i run them off as background processes then they don't
have any parents (parent becomes init or 1).. so i can't
figure how to keep the parent child links as well.
I would really really appreciate it if someone can help me with what
logic i should use to write this out..
Thanks
d
I want to read commands from a file and execute 5 of them
simultaneously. Then if any command(s) finish running, I
want to continue reading from the file and executing the
commands such that at any 1 time, there are always, say, 5
processes running.
This script however should be able to have multiple instances
of it running as well, so for example a usage of:
myscript 1 5
and an input file containing:
1 sleep 40
1 sleep 45
1 sleep 32
1 sleep 34
1 sleep 34
1 sleep 34
1 sleep 34
1 sleep 34
1 sleep 34
1 sleep 34
1 sleep 34
1 sleep 34
1 sleep 34
1 sleep 34
1 sleep 34
1 sleep 40
etc..
should execute the first 5 sleeps then if 2 sleeps finish I
should be able to read and execute 3 more...etc
I can do this successfully if my logic greps for sleep and
I just call the script once. But,
I should *also* be able to fire off
myscript 2 5 (run commands beginning with 2, keeping 5 running)
and
myscript 4 4 (run commands beginning with 4, keeping 4 running)
here myscript 2 5 would read in from file as below, say,
2 sleep 34
2 sleep 32
2 sleep 99
2 sleep 80
2 sleep 70
2 sleep 50
2 sleep 80
2 sleep 30
2 sleep 80
2 sleep 40
2 sleep 10
2 sleep 81
2 sleep 20
etc
so if I simultaneously run
myscript 1 5
myscript 2 5
then I cannot depend on grep sleep *and* keep the counts proper.
If i run them off as background processes then they don't
have any parents (parent becomes init or 1).. so i can't
figure how to keep the parent child links as well.
I would really really appreciate it if someone can help me with what
logic i should use to write this out..
Thanks
d