popen()/pclose()에 대한 몇 가지 구현을 보았습니다.popen-locks 또는 thread safe하지 않습니까?
static int *pids;
static int fds;
if (!pids) {
if ((fds = getdtablesize()) <= 0)
return (NULL);
if ((pids = malloc(fds * sizeof(int))) == NULL)
return (NULL);
memset(pids, 0, fds * sizeof(int));
}
또는이, 가정 NetBSD의 : - A는 안전 구현을 스레드하지 그것이 어떻게 생겼는지
static struct pid {
struct pid *next;
FILE *fp;
pid_t pid;
} *pidlist;
/* Link into list of file descriptors. */
cur->fp = iop;
cur->pid = pid;
cur->next = pidlist;
pidlist = cur;
가 그들 모두의 PID의 정적 목록없이 잠금을 사용? 또는 나는 명백한 것을 놓치고 있는가?
예, 어린이 목록을 잠급니다. 이것은 훨씬 낫다. 링크를 가져 주셔서 감사합니다. 필자는 pid를 리턴 한 popen을 원했고 pclose로 전달했지만,이 경우 libc 옵션이 아닙니다. –