Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: Use running system processes and filter them on different ways

by daxim (Curate)
on May 20, 2019 at 12:03 UTC ( [id://11100277]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Use running system processes and filter them on different ways
in thread Use running system processes and filter them on different ways

procsf is a file holding system processes information
No, it's a file system (hence procfs) expressed as a whole hierarchy of directories and files.
How is procsf different from the top command
top and similar tools read files from procfs to aggregate and display process info. You don't need to read top output, you can read procfs yourself, which is more efficient and puts you fully in control. It's the same idea that you do not spawn ls, but use opendir/readdir/stat to get file info.
how can I make use of it effectively
man 5 proc

These are simple files, you already know how to open files and read from them. It makes no difference that the files are virtual and do not reside on some permanent storage. That's one of the design goals in unix.

Replies are listed 'Best First'.
Re^4: Use running system processes and filter them on different ways
by afoken (Chancellor) on May 20, 2019 at 21:13 UTC

    Also note that the contents of the procfs tree (typically mounted at /proc highly depends on both the operating system and the operating system version. Given any generic Unix-like system, I would expect to find one directory per running process, using the process ID as the directory name, and perhaps tons of OS-specific stuff. Inside the PID directories, I would expect to find even more OS-specific stuff. Note the term "OS-specific stuff", meaning exactly that. An unspecified amount (maybe even zero) of unspecified directory entries.

    Just for fun, I've just logged into my pfSense box (currently running pfSense v2.4.4-RELEASE). It is based on FreeBSD 11.2-RELEASE-p3. And guess how /proc looks like there:

    [2.4.4-RELEASE][root@pfSense]/root: ls /proc [2.4.4-RELEASE][root@pfSense]/root: ls -alF /proc total 8 dr-xr-xr-x 2 root wheel 512 Jul 19 2016 ./ drwxr-xr-x 22 root wheel 1024 Feb 2 17:47 ../ [2.4.4-RELEASE][root@pfSense]/root:

    Yes, it's empty, to my surprise. pfSense works fine without it. Now imagine a tool insisting on having data in /proc ...

    You can still mount it:

    [2.4.4-RELEASE][root@pfSense]/root: mount /dev/ufsid/5895f1e0f622b3ed on / (ufs, local, journaled soft-updates) devfs on /dev (devfs, local) /dev/md0 on /var/run (ufs, local) devfs on /var/dhcpd/dev (devfs, local) [2.4.4-RELEASE][root@pfSense]/root: mount -t procfs proc /proc [2.4.4-RELEASE][root@pfSense]/root: ls -alF /proc total 4 dr-xr-xr-x 1 root wheel 0 May 20 23:06 ./ drwxr-xr-x 22 root wheel 1024 Feb 2 17:47 ../ dr-xr-xr-x 1 root wheel 0 May 20 23:06 0/ dr-xr-xr-x 1 root wheel 0 May 20 23:06 1/ dr-xr-xr-x 1 root wheel 0 May 20 23:06 10/ # many directories cut away dr-xr-xr-x 1 dhcpd _dhcp 0 May 20 23:06 65493/ dr-xr-xr-x 1 root wheel 0 May 20 23:06 7/ dr-xr-xr-x 1 root wheel 0 May 20 23:06 72338/ # more directories cut away dr-xr-xr-x 1 root wheel 0 May 20 23:06 98163/ lr--r--r-- 1 root wheel 0 May 20 23:06 curproc@ -> 85721 [2.4.4-RELEASE][root@pfSense]/root: ls -alF /proc/7 total 0 dr-xr-xr-x 1 root wheel 0 May 20 23:07 ./ dr-xr-xr-x 1 root wheel 0 May 20 23:07 ../ -r--r--r-- 1 root wheel 0 May 20 23:07 cmdline --w------- 1 root wheel 0 May 20 23:07 ctl -r--r--r-- 1 root wheel 0 May 20 23:07 etype -r--r--r-- 1 root wheel 0 May 20 23:07 rlimit -r--r--r-- 1 root wheel 0 May 20 23:07 status [2.4.4-RELEASE][root@pfSense]/root:

    Compared with Linux, this is procfs on a strict diet. See also https://www.freebsd.org/doc/en/articles/linux-users/procfs.html.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11100277]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-25 10:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found