I'm using virtual file-system in /proc/ to print out 1) current working directory (CWD): ls /proc/$PID/cwd
2) command line*: cat /proc/$PID/cmdline
and 3) # of open files: ls /proc/$PID/fdinfo | wc -l
All above snippets are part of printfs.
Now, some processes complain about SUDO privileges (e.g. init: ls: cannot access /proc/1/cwd: Permission denied).
Is it possible to know beforehand if action/command will require SUDO? For example, is there a "maximum PID number", above which no process needs SUDO?
Following snippet checks if user ran the script as SUDO, but I'd need to know beforehand if there will be an "error": if [ $UID -eq 0 ] ; then
BTW: In following printf snippet with 2 arguments, printf "%15s %s\n" CWD: "$((ls /proc/$PID/cwd) | tr '\n' ' ')"
if ls returns error cannot open directory /proc/1/fd: Permission denied it outputs this error before "CWD:", like so:
ls: cannot access /proc/1/cwd: Permission denied
CWD:
Why this happens?
- tldp.org says that
so I'm not sure if "command-line arguments" is what was meant by "command line".