github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/osext/demo.go (about)

     1  // Copyright 2013 <chaishushan{AT}gmail.com>. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // +build ignore
     6  
     7  package main
     8  
     9  import (
    10  	"fmt"
    11  	"os"
    12  	"os/signal"
    13  	"syscall"
    14  
    15  	myos "."
    16  )
    17  
    18  func main() {
    19  	fl, err := myos.NewFileLock("demo.lock")
    20  	if err == nil {
    21  		fmt.Printf("Lock Success!\n")
    22  		defer fl.Release()
    23  	} else {
    24  		fmt.Printf("Lock Failed!\n")
    25  	}
    26  
    27  	ch := make(chan os.Signal, 1)
    28  	signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
    29  	fmt.Printf("Quit (%v)\n", <-ch)
    30  }