[問題] unistd.h & wait.h
看板C_and_CPP (C/C++)作者devil115789 (味噌湯好喝)時間14年前 (2011/10/18 13:56)推噓2(2推 0噓 18→)留言20則, 5人參與討論串1/2 (看更多)
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
VC++
問題(Question):
VC++沒有內建的unistd和sys/wait.h
預期的正確結果(Expected Output):
看到書上介紹的fork用法
錯誤結果(Wrong Output):
'wait.h': No such file or directory
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#include <wait.h>
int main()
{
pid_t pid;
pid = fork();
if(pid < 0)
{
fprintf(stderr, "Fork Failed");
return 1;
}
else if (pid == 0)
{
execlp("/bin/ls","ls",NULL);
}
else
{
wait(NULL);
printf("Child Complete");
}
return 0;
}
補充說明(Supplement):
書上沒有sys/wait.h這一項
不加的話wait無法識別
但是查了一下卻也是linux上的指令
而unistd是看了網路上的解決方法處理(自己定義header)
目前還沒compile過所以不知道有沒有問題
煩請解答 感恩!
謝謝各位的解答
/var/tmp//ccYqIclx.o(.eh_frame+0x12): undefined reference to
`__gxx_personality_v0'
用學校的工作站跑變成這樣子了 0.0
再次請問一下..
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.90.83
→
10/18 13:58, , 1F
10/18 13:58, 1F
→
10/18 13:59, , 2F
10/18 13:59, 2F
→
10/18 13:59, , 3F
10/18 13:59, 3F
→
10/18 13:59, , 4F
10/18 13:59, 4F
→
10/18 14:11, , 5F
10/18 14:11, 5F
推
10/18 14:21, , 6F
10/18 14:21, 6F
※ 編輯: devil115789 來自: 140.113.90.83 (10/18 14:29)
※ 編輯: devil115789 來自: 140.113.90.83 (10/18 14:29)
→
10/18 14:30, , 7F
10/18 14:30, 7F
→
10/18 14:32, , 8F
10/18 14:32, 8F
→
10/18 14:33, , 9F
10/18 14:33, 9F
→
10/18 14:34, , 10F
10/18 14:34, 10F
→
10/18 14:41, , 11F
10/18 14:41, 11F
→
10/18 14:43, , 12F
10/18 14:43, 12F
→
10/18 14:43, , 13F
10/18 14:43, 13F
→
10/18 14:56, , 14F
10/18 14:56, 14F
→
10/18 15:38, , 15F
10/18 15:38, 15F
推
10/18 15:43, , 16F
10/18 15:43, 16F
→
10/18 15:44, , 17F
10/18 15:44, 17F
→
10/18 15:45, , 18F
10/18 15:45, 18F
→
10/18 15:48, , 19F
10/18 15:48, 19F
→
10/18 15:57, , 20F
10/18 15:57, 20F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章