跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

procname.go

43 行 · 1.3 KB历史下载
1package vm
2
3import (
4 "os"
5 "os/exec"
6 "path/filepath"
7 "runtime"
8 "strconv"
9 "strings"
10
11 "github.com/lima-vm/lima/v2/pkg/limatype"
12 "github.com/lima-vm/lima/v2/pkg/limatype/filenames"
13)
14
15// isQEMU reports whether pid is the QEMU of the VM name, whose files are in
16// dir: its command line has the -name and -pidfile Lima gave it. A PID file
17// outlives a QEMU that aborted, and its number may belong to another program
18// or another VM by now: that one must not be killed.
19func isQEMU(pid int, dir, name string) bool {
20 var args string
21 switch runtime.GOOS {
22 case "linux":
23 b, err := os.ReadFile("/proc/" + strconv.Itoa(pid) + "/cmdline")
24 if err != nil {
25 return false
26 }
27 args = strings.ReplaceAll(string(b), "\x00", " ")
28 case "windows":
29 return isWindowsQEMU(pid, dir, name)
30 default:
31 out, err := exec.Command("ps", "-p", strconv.Itoa(pid), "-o", "args=").Output()
32 if err != nil {
33 return false
34 }
35 args = string(out)
36 }
37 // Padded, so that an option is matched whole.
38 args = " " + strings.TrimSpace(args) + " "
39 pidfile := filepath.Join(dir, filenames.PIDFile(string(limatype.QEMU)))
40 prog, _, found := strings.Cut(args, " -name lima-"+name+" ")
41 return found && strings.Contains(strings.ToLower(prog), "qemu") &&
42 strings.Contains(args, " -pidfile "+pidfile+" ")
43}