0

My university professor has asked me to develop a project in C for Unix machines. I should do a soccer championship emulator, in which there is a parent, and there are some child(every match between two teams). The parent must create the matches, and the matches must tell the end result to the parent.

I think the best thing to do is to use fork() syscall and unnamed pipes.

What do you think about?

Thanks

3
  • 2
    unnamed pipes will work, but note that a pipe is uni-directional. If you want bi-directional communication over a single file-descriptor, you might want to use socketpair() instead. Commented Apr 29, 2014 at 19:50
  • 1
    So, i can use only one socketpair() instead of using one pipe for every match/child? Commented Apr 29, 2014 at 20:06
  • 1
    One socketpair per child (creating two file descriptors per child), rather than two pipes per child (creating four file descriptors per child). Commented Apr 29, 2014 at 22:41

1 Answer 1

1

Your suggestion above is valid. That approach would work. It might be easier to use a chunk of shared memory and mutex instead, but it's ultimately your call. I've included a working example that uses pthread_mutex calls and mmap in the references below that should get you up and running. Good luck!

References


  1. C procs, fork(), and mutexes, Accessed 2014-04-29, <https://stackoverflow.com/questions/19172541/procs-fork-and-mutexes>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.