MacOS下ProcStat解析问题
- Dominant language
- C++
- Stars
- 17.6k
- Forks
- 4.1k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 69
Description
**Describe the bug (描述bug)**
使用master分支,macos运行时抛出报警
```W0429 15:16:10.554731 236433408 default_variables.cpp:117] Fail to sscanf: Undefined error: 0 [0]```
**Versions**
OS: macOS High Sierra 1013.6
**Additional context/screenshots (更多上下文/截图)**
相关报警代码位置:https://github.com/apache/incubator-brpc/blob/master/src/bvar/default_variables.cpp#L99-L118
```c++
#elif defined(OS_MACOSX)
// TODO(zhujiashun): get remaining state in MacOS.
memset(&stat, 0, sizeof(stat));
static pid_t pid = getpid();
std::ostringstream oss;
char cmdbuf[128];
snprintf(cmdbuf, sizeof(cmdbuf),
"ps -p %ld -o pid,ppid,pgid,sess"
",tpgid,flags,pri,nice | tail -n1", (long)pid);
if (butil::read_command_output(oss, cmdbuf) != 0) {
LOG(ERROR) << "Fail to read stat";
return -1;
}
const std::string& result = oss.str();
if (sscanf(result.c_str(), "%d %d %d %d"
"%d %u %ld %ld",
&stat.pid, &stat.ppid, &stat.pgrp, &stat.session,
&stat.tpgid, &stat.flags, &stat.priority, &stat.nice) != 8) {
PLOG(WARNING) << "Fail to sscanf";
return false;
}
```
在本地mac下ps -p PID -o "pid,flags"发现flags字符串是16进制格式,例如"400e",使用%u解析会出错。
Contributor guide
Research direction
Start in src/bvar/default_variables.cpp around lines 99-118 and inspect the macOS ps command output and its sscanf format. Reproduce the warning on macOS and verify the flags field format; done means ProcStat parsing accepts the reported output without the Fail to sscanf warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100