How can I get the command arguments or the whole command line from a running process using its process name?For example this process:# psPID   USER     TIME   COMMAND 1452 root       0:00 /sbin/udhcpc -b -T 1 -A 12 -i eth0 -p /var/run/udhcpc.eth0.pidAnd what I want is /sbin/udhcpc -b -T 1 -A 12 -i eth0 -p /var/run/udhcpc.eth0.pid or the arguments. I know the process name and want its arguments. I'm using Busybox on SliTaz.
How to get whole command line from a process?
scripting;process;ps;busybox
You could use the -o switch to specify your output format:$ ps -eo argsFrom the man page:Command with all its arguments as a string. Modifications to the arguments may be shown. [...]You may also use the -p switch to select a specific PID:$ ps -p [PID] -o argspidof may also be used to switch from process name to PID, hence allowing the use of -p with a name:$ ps -p $(pidof dhcpcd) -o argsOf course, you may also use grep for this (in which case, you must add the -e switch):$ ps -eo args | grep dhcpcd | head -n -1GNU ps will also allow you to remove the headers (of course, this is unnecessary when using grep):$ ps -p $(pidof dhcpcd) -o args --no-headersOn other systems, you may pipe to AWK or sed:$ ps -p $(pidof dhcpcd) -o args | awk 'NR > 1'$ ps -p $(pidof dhcpcd) -o args | sed 1dEdit: if you want to catch this line into a variable, just use $(...) as usual:$ CMDLINE=$(ps -p $(pidof dhcpcd) -o args --no-headers)or, with grep :$ CMDLINE=$(ps -eo args | grep dhcpcd | head -n -1)