@@ -465,23 +465,30 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i
465465 }
466466 else
467467 {
468- snprintf (procFilePath , sizeof (procFilePath ), "/proc/%d/"
469- #if __GNU__
470- "cmdline"
471- #else
472- "comm"
473- #endif
474- , (int )pid );
468+ #ifndef __GNU__
469+ snprintf (procFilePath , sizeof (procFilePath ), "/proc/%d/comm" , (int )pid );
475470 ssize_t nRead = ffReadFileBuffer (procFilePath , name );
476471 if (nRead <= 0 )
477- return "ffReadFileBuffer(/proc/pid/"
478- #if __GNU__
479- "cmdline"
480- #else
481- "comm"
482- #endif
483- ", name) failed" ;
472+ return "ffReadFileBuffer(/proc/pid/comm, name) failed" ;
484473 ffStrbufTrimRightSpace (name );
474+ #else
475+ // No /proc/1/comm on Hurd so read /proc/1/stat again
476+ snprintf (procFilePath , sizeof (procFilePath ), "/proc/%d/stat" , (int )pid );
477+ char buf [PROC_FILE_BUFFSIZ ];
478+ ssize_t nRead = ffReadFileData (procFilePath , sizeof (buf ) - 1 , buf );
479+ if (nRead <= 8 )
480+ return "ffReadFileData(/proc/pid/stat, PROC_FILE_BUFFSIZ-1, buf) failed" ;
481+ buf [nRead ] = '\0' ;
482+
483+ const char * start = memchr (buf , '(' , (size_t ) nRead );
484+ if (!start )
485+ return "memchr(stat, '(') failed" ;
486+ start ++ ;
487+ const char * end = memchr (start , ')' , (size_t ) nRead - (size_t ) (start - buf ));
488+ if (!end )
489+ return "memchr(stat, ')') failed" ;
490+ ffStrbufSetNS (name , (uint32_t ) (end - start ), start );
491+ #endif
485492 }
486493
487494 #elif defined(__APPLE__ )
0 commit comments