How to list all process directories under /proc/
    Ky-Anh Huynh 
    saigon at example.net
       
    Sun Sep 17 08:32:24 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
My bad. Range doesn't support. The correct pattern is
[code]
   foreach (string fstatm; dirEntries("/proc/", "[0123456789]*", 
SpanMode.shallow)) {
     writefln("pid %s", fstatm);
   }
[/code]
Is there a way to make this simpler?
    
    
More information about the Digitalmars-d-learn
mailing list