Alright.. I have to rewrite a program. The thing is, I have to rewrite it using parent and children... With processes (pipes) or threads...

How do you create the parents and children with either of these?

I am basically asking for a tutorial on how you would create these with either processes or pipes... in C.

Could I have an example please?

We got absolutely no examples in class and I would really appreciate some guidance!


Recommended Answers

All 9 Replies

I can tell you on unix. To create a parent, you run a process.
To create a child for this process, use fork.
further is family of exec() function's.

See "Chapter 2: Processes and Threads" for lecture notes with sample code, and see "Writing a Shell" (which mentions pipes and reading and writing), with sample code.

(Using Unix of course.)

thanks for the help guys... ill get to reading..

and it was for unix (sorry i didnt specify)

i have to create a perent/children process in c++... is there any way to do it as in c?

Yeah, just use the same methods, you can link to C libraries from a C++ executable as well. I.e. use C apis in C++ code also. I think on unix the apis are in pthread lib if you want POSIX

so, all i have to do to use a c library is copy the *.c file into the directory where i have my .cpp and call it in the program with an #include "*.c" ?

so, all i have to do to use a c library is copy the *.c file into the directory where i have my .cpp and call it in the program with an #include "*.c" ?

You never #include .c files. To use a library, the general steps are:

  1. Copy all the header files (.h) into a general directory that the compiler reads.
  2. Copy the library files (.lib) into another directory that the linker reads.
  3. In your project, you have to make sure that the compiler and linker paths are setup to the directories where you put the .libs and headers files.
  4. #include all the header files in your source code.
  5. Add the names of the .libs in your linker options.

And dynamic libraries have .dlls that your program has to link to when it runs, but your OS takes care of that (usually).

You should also note that steps 1-2 are usually completed by the installer when you download the library.

hmm... but, since my conio library didn't work correctly (Using Dev's c++), i managed to obtain a new library, with which i have to #include the "conio.c" file, instead of the usual <conio.h> file... and that's how i use my conio library ever since...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.