ehds commented on code in PR #3602:
URL: https://github.com/apache/brpc/pull/3602#discussion_r4267136486
##########
src/bvar/default_variables.cpp:
##########
@@ -107,25 +110,76 @@ static bool read_proc_status(ProcStat &stat) {
}
return true;
#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 false;
+ const pid_t pid = getpid();
+ stat.pid = pid;
+ stat.ppid = getppid();
+ stat.pgrp = getpgrp();
+ const pid_t session = getsid(0);
+ stat.session = session >= 0 ? session : 0;
+ errno = 0;
+ const int nice = getpriority(PRIO_PROCESS, 0);
+ if (errno == 0)
+ stat.nice = nice;
+ struct proc_bsdinfo bsd = {};
Review Comment:
stat is already value-initialized at the beginning of `read_proc_status()`
via `stat = ProcStat()`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]