Skip to content

Instantly share code, notes, and snippets.

@jedy
Created November 29, 2012 08:11

Revisions

  1. jedy created this gist Nov 29, 2012.
    30 changes: 30 additions & 0 deletions lock.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    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)
    }