[問題] 關於 vfork 的問題
最近在自學一些有關 fork 的知識,
以下是抄來的例子
/* b01.c */
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
int main(void)
{
pid_t pid;
pid = vfork();
if (pid == 0) {
for (int j = 0; j < 10; j++) {
printf("child: %d\n", j);
sleep(1);
}
_exit(0); /* Note that we do not use exit() */
} else if (pid > 0) {
for (int i = 0; i < 10; i++) {
printf("parent: %d\n", i);
sleep(1);
}
exit(0);
} else {
fprintf(stderr, "can't fork, error %d\n", errno);
exit(1);
}
}
/* --- */
$gcc b01.c -g -o b01.out -std=c99
b01.c: In function 'main':
b01.c:12: warning: implicit declaration of function 'vfork'
我是在 Fedora 11的環境,
就我在別的地方看到的 vfork 好像定義在 unistd.h
可是我只找到一行
extern __pid_t vfork (void) __THROW;
至少在 /usr/include 我都沒找到其他 .h 的檔有 vfork
可是 b01.out 還是可以執行,結果也對,
請問, 上面那個 warning 是怎麼回事 ?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 71.198.44.240
→
08/15 12:20, , 1F
08/15 12:20, 1F
→
08/15 12:20, , 2F
08/15 12:20, 2F
→
08/15 12:21, , 3F
08/15 12:21, 3F
→
08/15 12:32, , 4F
08/15 12:32, 4F
→
08/15 12:39, , 5F
08/15 12:39, 5F
→
08/15 14:02, , 6F
08/15 14:02, 6F
→
08/15 14:02, , 7F
08/15 14:02, 7F
→
08/15 14:02, , 8F
08/15 14:02, 8F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章