How to get current process name in linux?

后端 未结 7 1918
醉话见心
醉话见心 2020-12-01 05:49

How can I get the process name in C? The same name, which is in /proc/$pid/status. I do not want to parse that file. Is there any programmatic way of doing this

7条回答
  •  醉话见心
    2020-12-01 06:16

    If you cannot access argv[] in main(), because you are implementing a library, you can have a look at my answer on a similar question here.

    It basically boils down into giving you access to argc, argv[] and envp[] outside of main(). Then you could, as others have already correctly suggested, use argv[0] to retrieve the process name.

提交回复
热议问题