killProcessesUsing kills the processes that have the user data directory dir in their command line.
(dir string)
| 22 | // killProcessesUsing kills the processes that have the user data directory dir |
| 23 | // in their command line. |
| 24 | func killProcessesUsing(dir string) { |
| 25 | want := "--user-data-dir=" + dir |
| 26 | entries, err := os.ReadDir("/proc") |
| 27 | if err != nil { |
| 28 | return |
| 29 | } |
| 30 | self := os.Getpid() |
| 31 | for _, entry := range entries { |
| 32 | pid, err := strconv.Atoi(entry.Name()) |
| 33 | if err != nil || pid == self { |
| 34 | continue |
| 35 | } |
| 36 | cmdline, err := os.ReadFile("/proc/" + entry.Name() + "/cmdline") |
| 37 | if err != nil { |
| 38 | continue |
| 39 | } |
| 40 | for arg := range bytes.SplitSeq(cmdline, []byte{0}) { |
| 41 | if string(arg) == want { |
| 42 | syscall.Kill(pid, syscall.SIGKILL) |
| 43 | break |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | } |
no outgoing calls
no test coverage detected