Domain/Linux
Run commands with synchronization in shell.
yhcting
2016. 4. 20. 22:43
Environment : Ubuntu 14.04 Tools : sem, flock(recommend) > $ cat a.sh #!/bin/bash str=0123456789 for i in {1..7}; do str=$str$str done for i in {1..10}; do echo $str >> out # (*a) # sem "echo $str >> out" # (*b) # flock out -c "echo $str >> out" # (*c) done > $ cat runa #!/bin/bash id=$1 for i in {1..10}; do ./a.sh& done > $ cat runa2 #!/bin/bash for i in {1..10}; do ./runa& done > $ ./runa2 check --------------- $ cat parout | uniq | wc -l 1 --------------- if 1 => OK, otherwise not-syncronized!! (*a) ==> race condition!! : (*c) sem ==> error!(sem bug!!) (*b) flock ==> OK