考虑这个例子:
#include <stdio.h>
#include <unistd.h>
int main()
{
int pgid;
if ((pgid = getpgid(0)) == -1)
perror("getpgid");
else
printf("pgid : %dn", pgid);
}
当我在没有valgrind的情况下运行这个程序时,一切都很顺利,并且打印了pgid。 每当我使用 valgrind 时,perror
都会打印getpgid: Function not implemented
.
瓦尔格林德下没有
getpgid
正常吗?是否有其他方法可以获取特定 pid 的 pgid(不包括
getpgrp
) ?
我使用的是macOS Sierra 10.12.6和valgrind-3.15.0。
似乎 valgrind 在执行某些系统调用时可能会遇到一些麻烦。
在瓦尔格林德追踪中,我有:
--17135-- WARNING: unhandled amd64-darwin syscall: unix:151
--17135-- You may be able to write your own handler.
--17135-- Read the file README_MISSING_SYSCALL_OR_IOCTL.
--17135-- Nevertheless we consider this a bug. Please report
--17135-- it at http://valgrind.org/support/bug_reports.html.
所以我需要为函数创建一个包装器,它应该可以工作。 我会向支持人员报告该错误。
你不应该在Mac OS X上通过valgrind进行测试,因为在Sierra之后,它不受支持。相反,这也是我所做的,通过虚拟机软件安装 ubuntu,然后运行 valgrind。
macOS Mojave 10.14.6的unistd.h
具有以下部分,
#if __DARWIN_UNIX03
void encrypt(char *, int) __DARWIN_ALIAS(encrypt);
#else /* !__DARWIN_UNIX03 */
int encrypt(char *, int);
#endif /* __DARWIN_UNIX03 */
int fchdir(int);
long gethostid(void);
pid_t getpgid(pid_t);
pid_t getsid(pid_t);
经验法则,始终尝试便携!
顺便说一下,正如@Andrew Henle所提到的,pid_t
可以是系统依赖的类型。但是,它不应该是无符号类型以保持可移植性,因为它可以在失败的情况下作为-1
返回。此外,在Mac OS X上,其类型是int
,如下所示
typedef int __int32_t;
typedef __int32_t __darwin_pid_t; /* [???] process and group IDs */
typedef __darwin_pid_t pid_t;