3 Star 23 Fork 23

sheepbao / sms

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
pid.go 836 Bytes
一键复制 编辑 原始数据 按行查看 历史
boya 提交于 2017-03-29 09:24 . init
package main
import (
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
"sheepbao.com/glog"
)
// save pid
var CurDir string
func init() {
CurDir = getParentDirectory(getCurrentDirectory())
}
func getParentDirectory(dirctory string) string {
return substr(dirctory, 0, strings.LastIndex(dirctory, "/"))
}
func getCurrentDirectory() string {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
glog.Fatal(err)
}
return strings.Replace(dir, "\\", "/", -1)
}
func substr(s string, pos, length int) string {
runes := []rune(s)
l := pos + length
if l > len(runes) {
l = len(runes)
}
return string(runes[pos:l])
}
func SavePid() error {
pidFilename := CurDir + "/pid/" + filepath.Base(os.Args[0]) + ".pid"
pid := os.Getpid()
return ioutil.WriteFile(pidFilename, []byte(strconv.Itoa(pid)), 0755)
}
Go
1
https://gitee.com/sheepbao/sms.git
git@gitee.com:sheepbao/sms.git
sheepbao
sms
sms
7d1c39e4e9bc

搜索帮助