feat(实现功能): 实现功能

This commit is contained in:
xiaoqidun 2022-11-22 14:00:07 +08:00
parent bb66e73222
commit b789cb74fb
2 changed files with 39 additions and 2 deletions

View File

@ -1,3 +1,7 @@
# WslKD
Windows Subsystem for Linux Keep Daemon
Windows Subsystem for Linux Keep Daemon
# 简要说明
wsl在没有使用的情况下守护进程会被关闭本工具在指定的wsl发行版打开一个shell为wsl守护进程保活。

View File

@ -1,5 +1,38 @@
package main
func main() {
import (
"flag"
"github.com/xiaoqidun/gowsl"
"log"
"strings"
"sync"
)
func main() {
var d string
flag.StringVar(&d, "d", "Debian", "distribution")
flag.Parsed()
waitGroup := &sync.WaitGroup{}
distroList := strings.Split(d, ",")
for i := 0; i < len(distroList); i++ {
distro := strings.TrimSpace(distroList[i])
if distro == "" {
continue
}
waitGroup.Add(1)
go exec(waitGroup, distro)
}
waitGroup.Wait()
}
func exec(done *sync.WaitGroup, distro string) {
defer done.Done()
if !gowsl.Registered(distro) {
log.Printf("%v does not exist\n", distro)
return
}
cmd := gowsl.Command(distro, "/bin/bash")
if err := cmd.Run(); err != nil {
log.Printf("%v cmd run err: %v", distro, err)
}
}