|
|
@@ -17,3 +17,14 @@ func ExampleExec() {
|
|
|
err := unix.Exec("/bin/ls", []string{"ls", "-al"}, os.Environ())
|
|
|
log.Fatal(err)
|
|
|
}
|
|
|
+
|
|
|
+func ExampleFlock() {
|
|
|
+ f, _ := os.Create("example.lock")
|
|
|
+ if err := unix.Flock(int(f.Fd()), unix.LOCK_EX); err != nil {
|
|
|
+ log.Fatal(err)
|
|
|
+ }
|
|
|
+ // Do work here that requires the lock. When finished, release the lock:
|
|
|
+ if err := unix.Flock(int(f.Fd()), unix.LOCK_UN); err != nil {
|
|
|
+ log.Fatal(err)
|
|
|
+ }
|
|
|
+}
|