PDA

View Full Version : Linux background calculations


brydustin
May13-11, 05:29 PM
hi,
I'm running some calculations in the background of my Linux work computer, and I now have some more jobs for it to do, but the current calculations are not yet finished. For example, my new file, RUN.in has the following:
./cal1
./cal2
./cal3
./etc

and this is similar to what I have running right now in my first list, except that I want to "append the list".
Can I just go into the first List of calculations and literally add these new jobs, whilst the current ones are running (by adding the list of RUN.in to the end of the first list which looks like RUN.in).... or is it possible to run the new list of calculations under the list "RUN.in" but not do it manually after the first is finished (i.e. give the computer instructions to do it next even if i'm not present)
.... or is it possible to do either (i.e. append to list OR tell it to do the RUN.in list next)?
Help much appreciate thanx

Rogerio
May14-11, 12:15 PM
You can't insert the lines AFTER the shell is already running.

What about

user@host:/tmp$ RUN1.in &
[1] 1234
user@host:/tmp$ wait %1 ; RUN2.in &

Or maybe:

user@host:/tmp$ ( RUN1.in ; RUN2.in) &
[1] 2768

AlephZero
May14-11, 01:26 PM
If you want to do this sort of thing regularly, look at
http://en.wikipedia.org/wiki/Job_scheduler#Batch_queuing_for_HPC_clusters

Not all those apps are free software (and the ones I have used personally are not free) but it I bet somebody in the Linux community has written a freeware solution.

Don't be put off by the "high performance computing clusters" description. They are also useful for load-balancing on a single computer, which is what you are trying to do.

brydustin
May14-11, 02:15 PM
You can't insert the lines AFTER the shell is already running.

What about

user@host:/tmp$ RUN1.in &
[1] 1234
user@host:/tmp$ wait %1 ; RUN2.in &

Or maybe:

user@host:/tmp$ ( RUN1.in ; RUN2.in) &
[1] 2768

Specifically what will
user@host:/tmp$ wait %1 ; RUN2.in &
do?? I just want to be very careful not to make a mistake (i.e. the calculations are going now, and don't want to waste any time). Does "wait" mean that the new job is "waiting" for the first (current) one to finish? If so.... that's exactly what I want.

Rogerio
May15-11, 09:14 PM
Specifically what will
user@host:/tmp$ wait %1 ; RUN2.in &
do?? I just want to be very careful not to make a mistake (i.e. the calculations are going now, and don't want to waste any time). Does "wait" mean that the new job is "waiting" for the first (current) one to finish? If so.... that's exactly what I want.

Yes, it does. But... the "wait" has to be in foreground (or it won't know who is the "%1" job) at the SAME shell session where the "Job %1" is running.

Being so, maybe you prefer to use:
user@host:/tmp$ RUN1.in &
[1] 1234

And then, at ANY shell session (or any terminal):
user@host:/tmp$ (while kill -0 1234; do sleep 60; done); RUN2.in &

The "while" keeps testing the existence of the process 1234 (the first job PID) every 60 seconds, and, when it is gone, the "RUN2.in" command will be called.
The while will run on foreground, and the RUN2 at background.

If you prefer everything at background:
user@host:/tmp$ ((while kill -0 1234; do sleep 60; done); RUN2.in) &