Created
February 28, 2018 21:21
-
-
Save scriptnull/beefa8146aad8c7ead6936f12e02500c to your computer and use it in GitHub Desktop.
Opens same files from multiple processes.
This file contains hidden or 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" | |
| "log" | |
| "os" | |
| "golang.org/x/sys/unix" | |
| ) | |
| func main() { | |
| if len(os.Args) < 2 { | |
| log.Fatalln("Requires atleast one argument") | |
| } | |
| for _, filePath := range os.Args[1:] { | |
| // Example of filePath: /home/scriptnull/cool/code.js | |
| if filePath == "" { | |
| log.Fatalln("Requires a non-empty file path") | |
| } | |
| // Open the filePath | |
| fd, err := unix.Open(filePath, unix.O_RDWR|unix.O_CREAT, 0755) | |
| if err != nil { | |
| log.Fatalf("Error: %+v fd: %d \n", err, fd) | |
| } | |
| // Print the file Descriptor | |
| fmt.Printf("File descriptor value of %s is %d \n", filePath, fd) | |
| } | |
| // Run the process infinitely | |
| for { | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment