Skip to main content
Change code to a Python code block rather than a shell one. Add some formatting so it's possible to read.
Source Link
Peilonrayz
  • 44.6k
  • 7
  • 80
  • 158

All the solutions which are parsing /proc/$PID/stat manually are broken!

A process may contain a space character, and then changes the index of splitting it by whitespace:

python -c "import setproctitle, os, glob; setproctitle.setproctitle('foo bar baz'); [open(fn).read().split()[3] for fn in glob.glob('/proc/*/stat') if not os.path.isdir(fn)]"
import setproctitle, os, glob

setproctitle.setproctitle('foo bar baz')
[
    open(fn).read().split()[3]
    for fn in glob.glob('/proc/*/stat')
    if not os.path.isdir(fn)
]

All the solutions which are parsing /proc/$PID/stat manually are broken!

A process may contain a space character, and then changes the index of splitting it by whitespace:

python -c "import setproctitle, os, glob; setproctitle.setproctitle('foo bar baz'); [open(fn).read().split()[3] for fn in glob.glob('/proc/*/stat') if not os.path.isdir(fn)]"

All the solutions which are parsing /proc/$PID/stat manually are broken!

A process may contain a space character, and then changes the index of splitting it by whitespace:

import setproctitle, os, glob

setproctitle.setproctitle('foo bar baz')
[
    open(fn).read().split()[3]
    for fn in glob.glob('/proc/*/stat')
    if not os.path.isdir(fn)
]
added 10 characters in body
Source Link
Vogel612
  • 25.5k
  • 7
  • 59
  • 141

All the solutions which are parsing /proc/$PID/stat/proc/$PID/stat manually are broken!

A process may contain a space character, and then changes the index of splitting it by whitespace:

python -c "import setproctitle, os, glob; setproctitle.setproctitle('foo bar baz'); [open(fn).read().split()[3] for fn in glob.glob('/proc/*/stat') if not os.path.isdir(fn)]"

python -c "import setproctitle, os, glob; setproctitle.setproctitle('foo bar baz'); [open(fn).read().split()[3] for fn in glob.glob('/proc/*/stat') if not os.path.isdir(fn)]"

All the solutions which are parsing /proc/$PID/stat manually are broken!

A process may contain a space character, and then changes the index of splitting it by whitespace:

python -c "import setproctitle, os, glob; setproctitle.setproctitle('foo bar baz'); [open(fn).read().split()[3] for fn in glob.glob('/proc/*/stat') if not os.path.isdir(fn)]"

All the solutions which are parsing /proc/$PID/stat manually are broken!

A process may contain a space character, and then changes the index of splitting it by whitespace:

python -c "import setproctitle, os, glob; setproctitle.setproctitle('foo bar baz'); [open(fn).read().split()[3] for fn in glob.glob('/proc/*/stat') if not os.path.isdir(fn)]"
Minor grammar
Source Link
Stephen Rauch
  • 4.3k
  • 12
  • 24
  • 36

All the solutions which are parsing /proc/$PID/stat manually are broken!

aA process may contain a space character, and then changes the index of splitting it by whitespace:

python -c "import setproctitle, os, glob; setproctitle.setproctitle('foo bar baz'); [open(fn).read().split()[3] for fn in glob.glob('/proc/*/stat') if not os.path.isdir(fn)]"

All the solutions which are parsing /proc/$PID/stat manually are broken!

a process may contain a space character, and then changes the index of splitting it by whitespace:

python -c "import setproctitle, os, glob; setproctitle.setproctitle('foo bar baz'); [open(fn).read().split()[3] for fn in glob.glob('/proc/*/stat') if not os.path.isdir(fn)]"

All the solutions which are parsing /proc/$PID/stat manually are broken!

A process may contain a space character, and then changes the index of splitting it by whitespace:

python -c "import setproctitle, os, glob; setproctitle.setproctitle('foo bar baz'); [open(fn).read().split()[3] for fn in glob.glob('/proc/*/stat') if not os.path.isdir(fn)]"

Source Link
Loading