How to list all process directories under /proc/

angel andrey.gelman at gmail.com
Fri Sep 22 18:31:43 UTC 2017


On Sunday, 17 September 2017 at 08:15:58 UTC, Ky-Anh Huynh wrote:
> Hi,
>
> I want to list all processes by scanning /proc/. The following 
> code doesn't work
>
> [code]
>   foreach (string fstatm; dirEntries("/proc/", "[0-9]*", 
> SpanMode.shallow)) {
>     writefln("pid %s", fstatm);
>   }
> [/code]
>
> as it only list a few entries before exiting
>
> [code]
> pid /proc/9
> pid /proc/935
> pid /proc/9146
> pid /proc/9149
> pid /proc/9150
> pid /proc/9151
> pid /proc/9756
> pid /proc/9759
> pid /proc/9760
> pid /proc/9761
> [/code]
>
> I don't want to use `SpanMode.depth` or `SpanMode.breadth` 
> because it will scan so deeply and there would be a permission 
> problem.
>
> Any ideas?
>
> Thanks a lot


Are you familiar with libprocps ?
Maybe you had better make use of this library, or, at least, peek 
into its code, for reference.


More information about the Digitalmars-d-learn mailing list