Setting process name (as seen by `ps`) in Go

前端 未结 3 1861
名媛妹妹
名媛妹妹 2020-12-16 22:28

The following (rightfully) doesn\'t work:

package main

import (
        \"os\"
        \"time\"
)

func main() {
        os.Args[0] = \"custom name\"
               


        
3条回答
  •  有刺的猬
    2020-12-16 22:43

    To change a process name on Linux, you need to use the prctl system call combined with the PR_SET_NAME option.

    At the moment, I don't think you can do this in Go code. You can, however, build a small C module to do this and then integrate it into your Go build.

提交回复
热议问题