Start work on GNU

This commit is contained in:
Yelninei
2025-05-19 15:07:46 +00:00
committed by Carter Li
parent f2f9b10b18
commit 71fbe04367
8 changed files with 121 additions and 8 deletions
+21 -2
View File
@@ -234,7 +234,7 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
assert(processName->length > 0);
ffStrbufClear(exe);
#ifdef __linux__
#if defined(__linux__) || defined(__GNU__)
char filePath[64];
snprintf(filePath, sizeof(filePath), "/proc/%d/cmdline", (int)pid);
@@ -436,7 +436,7 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i
if (pid <= 0)
return "Invalid pid";
#ifdef __linux__
#if defined(__linux__) || defined(__GNU__)
char procFilePath[64];
if (ppid)
@@ -465,11 +465,30 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i
}
else
{
#ifndef __GNU__
snprintf(procFilePath, sizeof(procFilePath), "/proc/%d/comm", (int)pid);
ssize_t nRead = ffReadFileBuffer(procFilePath, name);
if(nRead <= 0)
return "ffReadFileBuffer(/proc/pid/comm, name) failed";
ffStrbufTrimRightSpace(name);
#else
// No /proc/1/comm on Hurd so read /proc/1/stat again
snprintf(procFilePath, sizeof(procFilePath), "/proc/%d/stat", (int)pid);
char buf[PROC_FILE_BUFFSIZ];
ssize_t nRead = ffReadFileData(procFilePath, sizeof(buf) - 1, buf);
if(nRead <= 8)
return "ffReadFileData(/proc/pid/stat, PROC_FILE_BUFFSIZ-1, buf) failed";
buf[nRead] = '\0';
ffStrbufEnsureFixedLengthFree(name, 255);
if(
sscanf(buf, "%*s (%255[^)]) %*c %*d %*d %*d %*d", name->chars) == 0 || //stat (comm) state ppid pgrp session tty
name->chars[0] == '\0'
)
return "sscanf(stat) failed";
ffStrbufRecalculateLength(name);
#endif
}
#elif defined(__APPLE__)