-1

I have to write a c code which will contain two processes. And its executable will be launched twice on two different terminals. Both processes will know whats their role. One terminal will show result of one process and second terminal will show result of second process. If i make two threads to create these two process can some one help me out that how both processes will recognize their role when launched on terminals?

1

Threads != processes

You could make the program take an argument that specifies which role it has and use a socket that one of the processes/modes creates and the other connect to.

  • Sorry I forgot to mention, i have to do this using semaphore and the role of both processes is to read from a text file but different parts of text file. – John Edgar Oct 11 '16 at 13:03
  • 1
    Why would they need a semaphore to do that? Both of them can open the file and read the correct part at the same time if neither of them change the contents of the file. --- It's also unclear if you're using threads or processes. -- It's also unclear how you start the two processes, because it doesn't make sense in the context. – Oskar Skog Oct 11 '16 at 13:39
  • Re: "I have to do this using semaphore and the role of both processes is to read from a text file but different parts of text file." Please add this to your original question - click on the edit link. – Mark Plotnick Oct 11 '16 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.