How to get the command line args passed to a running process on unix/linux systems?

后端 未结 13 565
梦谈多话
梦谈多话 2020-11-30 16:57

On SunOS there is pargs command that prints the command line arguments passed to the running process.

Is there is any similar command on other Unix env

相关标签:
13条回答
  • 2020-11-30 17:02

    You can use pgrep with -f (full command line) and -l (long description):

    pgrep -l -f PatternOfProcess
    

    This method has a crucial difference with any of the other responses: it works on CygWin, so you can use it to obtain the full command line of any process running under Windows (execute as elevated if you want data about any elevated/admin process). Any other method for doing this on Windows is more awkward ( for example ).
    Furthermore: in my tests, the pgrep way has been the only system that worked to obtain the full path for scripts running inside CygWin's python.

    0 讨论(0)
  • 2020-11-30 17:03

    Another variant of printing /proc/PID/cmdline with spaces in Linux is:

    cat -v /proc/PID/cmdline | sed 's/\^@/\ /g' && echo
    

    In this way cat prints NULL characters as ^@ and then you replace them with a space using sed; echo prints a newline.

    0 讨论(0)
  • 2020-11-30 17:05

    On Solaris

         ps -eo pid,comm
    

    similar can be used on unix like systems.

    0 讨论(0)
  • 2020-11-30 17:07

    You can simply use:

    ps -o args= -f -p ProcessPid
    
    0 讨论(0)
  • 2020-11-30 17:08

    Full commandline

    For Linux & Unix System you can use ps -ef | grep process_name to get the full command line.

    On SunOS systems, if you want to get full command line, you can use

    /usr/ucb/ps -auxww | grep -i process_name
    

    To get the full command line you need to become super user.

    List of arguments

    pargs -a PROCESS_ID
    

    will give a detailed list of arguments passed to a process. It will output the array of arguments in like this:

    argv[o]: first argument
    argv[1]: second..
    argv[*]: and so on..
    

    I didn't find any similar command for Linux, but I would use the following command to get similar output:

    tr '\0' '\n' < /proc/<pid>/environ
    
    0 讨论(0)
  • 2020-11-30 17:08

    Rather than using multiple commands to edit the stream, just use one - tr translates one character to another:

    tr '\0' ' ' </proc/<pid>/cmdline
    
    0 讨论(0)
提交回复
热议问题