0
我的目標是從Critical Section C
程序(Windows 7上的Visual Studio 2013)獲取輸出。我收到以下錯誤:錯誤LNK2019:無法解析的外部符號_vfork在函數_main中引用
error LNK2019: unresolved external symbol _vfork referenced in function _main
error LNK1120: 2 unresolved externals
我的代碼是
#include<stdio.h>
#include<sys/types.h>
#include<stdlib.h>
int turn;
int flag[2];
int main(void)
{
int pid, parent = 1;
printf("before vfork\n");
if ((pid = vfork())<0)
{
perror("vfork error\n");
return 1;
}
while (1)
{
if (pid == 0)
{
while (parent == 1)
{
sleep(2);
}
parent = 0;
flag[0] = 1;
turn = 1;
while (flag[1] && turn == 1);
printf("This is critical section:parent process\n");
flag[0] = 0;
}
else
{
parent = 2;
printf("This is parent");
flag[1] = 1;
turn = 0;
while (flag[0] && turn == 0);
printf("This is critical section:child process %d \n", pid);
flag[1] = 0;
}
}
}
我想也許OP打算使用[Cygwin](http://stackoverflow.com/q/985281/1174378)... –
親愛的黃昏,謝謝你的信息。由於保持開發工具和操作系統不是強制性的,我可以使用任何操作系統實現相同的概念。對於Unix,Linux可以支持這個程序嗎?如果是,那麼Ubunto 10? –
是的,Linux就是這樣一個系統。但是,請記住我要添加到我的文章中的註釋。 – duskwuff