LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-11-2022, 02:05 AM   #1
klmcguire
LQ Newbie
 
Registered: Feb 2022
Posts: 9

Rep: Reputation: 0
Waiting for all files to finish writing before continuing


I am automating a certain process using Linux Bash. Let's say I submit 5 jobs to 5 separate nodes and they write certain output files. I want to wait for all of those output files to finish writing before moving on to the next process in my program. However, each job takes a different amount of time to finish. The current version of my "wait" code is below. Each filename includes an integer starting at one (i.e. job1, job2, job3, job4, job5, etc). $k is the last file in that list, in this example and code below, it would be equilibration5.check. Ok, so the problem is equilibration5.check could be be created before, let's say, equilibration3.check depending if equilibration5 got a faster node than equilibration3. Well, in my code it would move on to the next part before allowing equilibration3 to finish and write equilibration3.check. The next code snippet would then check all of the existing equilibration.check files for "DONE" and then move on to the next process, possibly before some of the other .check files exist.

So, what is the best way to make my program wait until all of the .check files exist, regardless of what order they finish?



FILE=~/$a/MinAnnealEquilMD/Restart_Junk/equilibration$k.check
while test ! -f $FILE
do
sleep 2;
done


until false | grep -q "DONE" ~/$a/MinAnnealEquilMD/Restart_Junk/equilibration*.check
do
sleep 2
done
 
Old 03-11-2022, 02:19 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,335
Blog Entries: 3

Rep: Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731
There are several ways. The wait command, which is built-in, will pause until all processes finish before proceeding. If you combine that with functions, it could be structured like this:

Code:
#!/bin/sh

aaa() {
        sleep 10
        echo AAA done
}

bbb() {
        sleep 10
        echo BBB done
}

ccc() {
        sleep 10
        echo CCC done
}

aaa &
bbb &
ccc &

echo Waiting 
wait
echo Finished waiting 

exit 0
The built-in wait command found in Bash has additional capabilities. See "man sh" and "man bash". Both manual pages are quite long so to maximize their utility, get comfortable navigating them and using the shortcuts available in the man utility.
 
Old 03-11-2022, 04:01 AM   #3
klmcguire
LQ Newbie
 
Registered: Feb 2022
Posts: 9

Original Poster
Rep: Reputation: 0
Thanks for the reply. What if I'm sending the jobs off through sbatch and I want them to all run at the same time, but wait for all of them to finish?
 
Old 03-11-2022, 04:33 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,985

Rep: Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337
is it this sbatch?
you can get job details with scontrol.
 
Old 03-11-2022, 04:36 AM   #5
klmcguire
LQ Newbie
 
Registered: Feb 2022
Posts: 9

Original Poster
Rep: Reputation: 0
Yes it is that sbatch. How would I use scontrol in this context?
 
Old 03-12-2022, 06:51 AM   #6
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by klmcguire View Post
Yes it is that sbatch. How would I use scontrol in this context?
Is it this scontrol?
 
Old 03-12-2022, 09:13 AM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,679
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
Also the sync command. (Or the sync() system call.) This forces all pending disk-writes to be completed.

A simple way to handle this would be to write a program or script which "forks" a set of child processes to perform each task, then waits for all of them to finish. Each process ends with a "sync" call to make sure that all physical I/O is completed before it ends.
 
Old 03-12-2022, 10:09 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,985

Rep: Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337
Quote:
Originally Posted by ondoho View Post
yes, they belong to this slurm suite: https://slurm.schedmd.com/overview.html
I don't think someone can use it properly without knowing it (like me).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Waiting for a file to copy before continuing processing (Python) dsmyth Programming 2 03-25-2010 08:32 AM
My browser, all day today: 'waiting for linuxquestions.org...' ..waiting.. waiting .. GrapefruiTgirl LQ Suggestions & Feedback 18 05-25-2007 05:35 AM
Printer Configuration: "Print file sent, waiting for printer to finish", JetDirect Ed-MtnBiker Fedora 3 02-23-2007 12:41 PM
Cups: Print file sent, waiting for printer to finish.. Gurr Linux - Newbie 2 07-24-2006 06:42 AM
waiting for a child process to finish execution in C cynthia_thomas Programming 2 05-26-2006 03:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration