help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] lock redicted file


From: Peng Yu
Subject: [Help-bash] lock redicted file
Date: Fri, 5 Jul 2019 13:06:58 -0500

Hi,

If I run the following two commands in two separate bash sessions
concurrently, output.txt will contain messed up results from both awk
runs.

awk -e 'BEGIN { for(i=1;i<10;++i) { print 100+i; system("sleep 1"); }
}' > output.txt
awk -e 'BEGIN { for(i=1;i<10;++i) { print i; system("sleep 1"); } }' >
output.txt

Is there a bash syntax to lock output.txt that ensuring the file
redirected by ">" is not written concurrently by more than one
process? Thanks.

-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]