forked from abramisola/go-coreutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexit.go
58 lines (47 loc) · 1.09 KB
/
exit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// exit.go (go-coreutils) 0.1
// Copyright (C) 2014, The GO-Coreutils Developers.
//
// Written By: Abram C. Isola
//
package main
import "os"
import "log"
import "fmt"
import "flag"
const (
help_text string = `
Usage: exit [OPTION]
exit from a program, shell or log out of a unix network
--help display this help and exit
--version output version information and exit
`
version_text = `
exit (go-coreutils) 0.1
Copyright (C) 2014, The GO-Coreutils Developers.
This program comes with ABSOLUTELY NO WARRANTY; for details see
LICENSE. This is free software, and you are welcome to redistribute
it under certain conditions in LICENSE.
`
)
// Get PID of Parent
var process = os.Getppid()
func main() {
help := flag.Bool("help", false, help_text)
version := flag.Bool("version", false, version_text)
flag.Parse()
if *help {
fmt.Println(help_text)
os.Exit(0)
}
if *version {
fmt.Println(version_text)
os.Exit(0)
}
pproc, err := os.FindProcess(process)
if err != nil {
log.Fatalln(err)
} else {
pproc.Kill()
}
}