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

Naramsim
  • 8,059
  • 6
  • 35
  • 43
  • 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. – Jeremy Friesner Apr 29 '14 at 19:50
  • 1
    So, i can use only one socketpair() instead of using one pipe for every match/child? – Naramsim Apr 29 '14 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). – Jeremy Friesner Apr 29 '14 at 22:41

1 Answers1

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>
Community
  • 1
  • 1
Cloud
  • 18,753
  • 15
  • 79
  • 153