Skip to content

Instantly share code, notes, and snippets.

@scriptnull
Created February 28, 2018 21:21
Show Gist options
  • Select an option

  • Save scriptnull/beefa8146aad8c7ead6936f12e02500c to your computer and use it in GitHub Desktop.

Select an option

Save scriptnull/beefa8146aad8c7ead6936f12e02500c to your computer and use it in GitHub Desktop.
Opens same files from multiple processes.
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