Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 22-Jul-11 19:46pm
v2
Comments
Philippe Mori 23-Jul-11 9:27am    
Do you want your program to be portable or you want to do Windows only development and you were using POSIX mainly because you know it (or have found sample code that use it)?

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

[EDIT]
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
 
Share this answer
 
v4
Comments
nk.dushila 23-Jul-11 2:28am    
@SA

ohhhh

It means in Windows we called it "Threads"

Thanks a Lot
Sergey Alexandrovich Kryukov 24-Jul-11 0:40am    
You are welcome.
What do you mean? Threads are called threads in all systems I know, including POSIX-based. When I started to work with Linux, there were only processes; and threads were introduced later. Old processed could be understood like newer single-thread-only process. The units of execution are always threads; processes just host one ore more thread and provide complete data isolation; this is a reason why IPC is needed; threads of the same process can freely share data; that's why thread synchronization primitives are needed.

If you think it makes sense for you, please formally accept the answer (green button).
If not yet, your follow-up questions are welcome.
--SA
Albert Holguin 23-Jul-11 13:39pm    
excellent answer and suggestions... i almost always prefer to use sockets over pipes...
Sergey Alexandrovich Kryukov 24-Jul-11 0:34am    
Thank you, Albert.
As to sockets, I can understand you, they provide more flexibility. Few months ago I faced with one limitation: with a blocking pipe function, a variant of the method with timeout is not provided. I suited our needs but I was surprised a bit.
--SA
nk.dushila 25-Jul-11 0:31am    
@SAKryukov

Thank you again.
That really helps me a lot.
Now i know that i am on right way.
:)
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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900