Created
November 29, 2012 08:11
-
-
Save jedy/4167513 to your computer and use it in GitHub Desktop.
file record lock in golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"syscall" | |
"unsafe" | |
) | |
func main() { | |
k := struct { | |
Type uint32 | |
Whence uint32 | |
Start uint64 | |
Len uint64 | |
Pid uint32 | |
}{ | |
syscall.F_WRLCK, | |
uint32(os.SEEK_SET), | |
0, | |
10, | |
0, | |
} | |
f, err := os.OpenFile("x", os.O_RDWR, 0666) | |
_, _, errno := syscall.Syscall(syscall.SYS_FCNTL, f.Fd(), uintptr(syscall.F_SETLKW), uintptr(unsafe.Pointer(&k))) | |
fmt.Println(errno) | |
b := make([]byte, 1) | |
os.Stdin.Read(b) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment