github.com/mckael/restic@v0.8.3/cmd/restic/background_linux.go (about)

     1  package main
     2  
     3  import (
     4  	"syscall"
     5  	"unsafe"
     6  
     7  	"github.com/restic/restic/internal/debug"
     8  )
     9  
    10  // IsProcessBackground returns true if it is running in the background or false if not
    11  func IsProcessBackground() bool {
    12  	var pid int
    13  	_, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(syscall.Stdin), syscall.TIOCGPGRP, uintptr(unsafe.Pointer(&pid)))
    14  
    15  	if err != 0 {
    16  		debug.Log("Can't check if we are in the background. Using default behaviour. Error: %s\n", err.Error())
    17  		return false
    18  	}
    19  
    20  	return pid != syscall.Getpgrp()
    21  }