New answers tagged

2

There is no portable way to get an unambiguous representation of the command line of another process. You didn't find the answer you're looking for because it's impossible. You either need to cope with an ambiguous representation, or to use a different method depending on which OS your code is running on, or to find someone who's done that work for you. The ...


1

As with the other answers, /proc/${PID}/cmdline is the key, and this is available on Linux, FreeBSD, and NetBSD. As an alternative to perl and some quite complex sed, observe that xargs with the common but not standard -0 can happily turn ␀-terminated strings into command arguments, and (as the question says) printf with the common but not standard %...


1

You can't precisely select a column based on the regex, but you could do this: ps -ef | awk ' /[E]NV-NAME/{ match($0, /[a-z]+\.[a-z]+\.[a-z]+\.[a-z]+/); print( $2 " " substr($0, RSTART, RLENGTH)) }' I've dropped the greps, made it multiline to be more legible, and you'...


2

Since you’re using Debian, your ps supports combined so-called “BSD-style” and “Unix-style” options, you can use the n option which uses numbers for WCHAN and USER: ps n -Af


1

You can achieve the same effect using this: ps -e -o command,pcpu | awk -v OFS=: -v ORS=, '/tx/ {print $1, $NF}' | sed 's/,$/\n/' This filters columns using ps options, uses AWK to filter the output, keep the first and last entries on each matching line, and change the field and record separators, and replaces the trailing comma with a newline.


0

The trick is to make sure you are killing the right process and only the ones that you want. This sounds simple, but so many people stuff it up. The worst way programatically is to do it by name. OK, so you said you cannot modify the parent. The right way if you could do that is to take the return value of the fork() call as it has the child PID. The PID is ...


Top 50 recent answers are included