MCPcopy Create free account
hub / github.com/SeeFlowerX/stackplz / FindPidByName

Function FindPidByName

cli/cmd/root.go:563–580  ·  view source on GitHub ↗
(name string)

Source from the content-addressed store, hash-verified

561}
562
563func FindPidByName(name string) []uint32 {
564 var pid_list []uint32
565 content, err := util.RunCommand("sh", "-c", "ps -ef -o name,pid,ppid | grep ^"+name)
566 if err != nil {
567 Logger.Printf("warn, no running process of %s", name)
568 return pid_list
569 }
570 lines := strings.Split(content, "\n")
571 for _, line := range lines {
572 parts := strings.Fields(line)
573 value, err := strconv.ParseUint(parts[1], 10, 32)
574 if err != nil {
575 panic(err)
576 }
577 pid_list = append(pid_list, uint32(value))
578 }
579 return pid_list
580}
581
582// Execute adds all child commands to the root command and sets flags appropriately.
583// This is called by main.main(). It only needs to happen once to the rootCmd.

Callers 1

persistentPreRunEFuncFunction · 0.85

Calls 1

RunCommandFunction · 0.92

Tested by

no test coverage detected