C语言中的管/叉(win32) [英] Pipe/Fork in C (win32)

查看:109
本文介绍了C语言中的管/叉(win32)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友

我必须使用不同的C程序,并且我想在它们之间实现进程间通信.我阅读了一些有关InterProcess Communication的文档,发现"Pipe"对我来说是最好的解决方案.

由于我的两个程序都使用"C语言",因此我开始用"C"实现该程序.当我从文档中读取内容时,我必须#include< unistd.h>用于pipe()和fork()函数.但是当我编译它时;编译器向我显示无法打开包含文件" unistd.h"的错误.这是在Turbo c ++编译器中.

此后,我转到"Dev-C ++",遇到了一个新错误"[链接器错误]未定义对`pipe'的引用."

比我在VC ++中尝试过相同的程序;在这里,我遇到了与Turbo-C ++中相同的错误.

实际上,我的系统上安装了Windows XP,现在我发现pipe()和fork()函数基本上来自POSIX库,该库是为UNIX,LINUX和MAC OS设计的(不适用于WINDOWS)

因此,Plz建议我使用相同功能运行相同程序所要做的事情

我必须使用其他库/函数/头文件吗???????


非常感谢Advance
Naveen Kumar Dushila

Hello Friends

I have to Different C Programs and i want to implement InterProcess Communication in between both of them. I have read some documentation on InterProcess Communication and I found that "Pipe" is best solution for me.

Than i started implementing this Program in ''C'' because my both programs are in ''C language''. As i read from documents i had to #include <unistd.h> for pipe() and fork() functions. But when i compiled it; Compiler show me an Error that "Unable to open Include file ''unistd.h''." This was in Turbo c++ compiler.

After this i moved on to ''Dev-C++'' there i met a new error "[Linker error] undefined reference to `pipe''."

Than i tried the same program in VC++; here i got same error as in Turbo-C++.

Actually I have windows XP installed on my system and now i found that pipe() and fork() functions are basically from POSIX Library that is designed for UNIX, LINUX, MAC OS (Not for WINDOWS)

So Plz suggest me what i have to do to run the same Program with same Functions
OR
I have to use other libraries/Functions/Header Files???????


Thanks a lot in Advance
Naveen Kumar Dushila

推荐答案

用于IPC的管道?使用命名管道: http://msdn.microsoft.com/zh-我们/library/aa365590%28v=vs.85%29.aspx [ http://msdn.microsoft.com /en-us/library/aa365799%28v=vs.85%29.aspx [ http://msdn.microsoft. com/en-us/library/ms684847%28v = vs.85%29.aspx [ http://msdn.microsoft.com/en-us/library/ms686760%28v=VS.85%29.aspx [ http://msdn.microsoft.com/en-us/library/aa246693%28v=vs.60%29.aspx [ http://social.msdn .microsoft.com/forums/zh-CN/vclanguage/thread/c727ae29-5a7a-42b6-ad0b-f6b21c1180b2 [多线程教程 [ http://www.relisoft.com/win32/active.html [ ^ ].

—SA
Pipes for IPC? Use Named Pipes: http://msdn.microsoft.com/en-us/library/aa365590%28v=vs.85%29.aspx[^].


Find some Named Pipe samples here: http://msdn.microsoft.com/en-us/library/aa365799%28v=vs.85%29.aspx[^].
[END EDIT]

For threading, use Thread functions, see http://msdn.microsoft.com/en-us/library/ms684847%28v=vs.85%29.aspx[^]. You also should learn using thread pools, see http://msdn.microsoft.com/en-us/library/ms686760%28v=VS.85%29.aspx[^].

With C++, better use _beginthread, _beginthreadex: http://msdn.microsoft.com/en-us/library/aa246693%28v=vs.60%29.aspx[^]. See also this discussion: http://social.msdn.microsoft.com/forums/en-US/vclanguage/thread/c727ae29-5a7a-42b6-ad0b-f6b21c1180b2[^].

You actually need to learn a lot more about thread synchronization primitives: events, critical sections, mutexes, semaphores and more. One often overlooked IPC approach is provided by sockets which were originally were designed for IPC, not networking. Please search MSDN for these topics.

This is a short CodeProject tutorial on threading in Windows: Multithreading Tutorial[^].

Another useful short tutorial: http://www.relisoft.com/win32/active.html[^].

—SA


您也可以考虑使用Boost.我从未尝试过任何与boost相关的线程的想法,因为我编写的所有多线程程序都是针对Windows的.

提高C ++库 [ ^ ]

第20章,线程 [ Windows上的posix [适用于Windows的POSIX [
You might also consider Boost. I never tried anythink related to threading with boost as all multithreaded program I wrote was for Windows...

boost C++ Librairies[^]

Chapter 20, Threads[^]

You could also look at the result of a search for posix on windows[^]

Here is a section on Wikepedia page on POSIX: POSIX for Windows[^]


这篇关于C语言中的管/叉(win32)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆