跳到主要内容

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

浏览文件

process_start_linux.go

35 行 · 824 B历史下载
1package cage
2
3import (
4 "bytes"
5 "os"
6 "strconv"
7 "strings"
8)
9
10// Linux start times are clock ticks since boot, so the boot ID keeps a PID
11// reused after a reboot from matching a record from the previous boot.
12func processStartToken(pid int) string {
13 if pid <= 0 {
14 return ""
15 }
16 boot, err := os.ReadFile("/proc/sys/kernel/random/boot_id")
17 if err != nil {
18 return ""
19 }
20 stat, err := os.ReadFile("/proc/" + strconv.Itoa(pid) + "/stat")
21 if err != nil {
22 return ""
23 }
24 // The command name may contain spaces or parentheses; fields resume after
25 // the last ')'. starttime is field 22, the 20th after the name.
26 i := bytes.LastIndexByte(stat, ')')
27 if i < 0 {
28 return ""
29 }
30 fields := strings.Fields(string(stat[i+1:]))
31 if len(fields) < 20 {
32 return ""
33 }
34 return strings.TrimSpace(string(boot)) + ":" + fields[19]
35}