Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I print the user and umask for all running processes?

The username is in column one and PID in column two of ps gaux, so I have:

ps gaux | awk '{print $2;}' | while read line ; do grep -i umask /proc/$line/status ; done

but is there a way to print the username as well?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I hope this helps

ps gaux | awk '{printf $1 " " ; system("grep Umask /proc/"$2"/status | tr -dc [:digit:]"); printf "\n"}'

Explanation:

  1. get output from ps
  2. print first column (username) and space
  3. run the grep and remove everything except the actual umask, which is a number (awk does not print the command output, it gets just printed directly from the subshells stdout)
  4. print a new line
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading