[SOLVED] Can't get 3 processes to work together in synchronization (C + Linux)
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Can't get 3 processes to work together in synchronization (C + Linux)
I have a process with 2 child processes which are paused, and i'm trying to get the main process to "wake" one of them using a signal, wait for it to finish, make it pause again and wake the other one, and so on, all of this inside a while loop.
Here is the important parts of the code:
Creating and saving the IDs of the main and two child processes:
Quite honestly, "if you intend to do that, you should just be using a subroutine."
The entire purpose of processes/threads is to define units of work that, once launched, can run to completion without interference from anybody. If, instead, you need to "do something, wait for it to finish, then do something else," then your design will be considerably simplified by instead using: a subroutine call.
- - -
P.S.: Please, kindly understand (and assume) that I am not making fun of you, nor making light of you, in saying this.
Firstly sundialsvcs is correct. This is a game where the context is global and the only thing which becomes unique is the ownership of the player. Thus you can branch one way versus another and stay within your main process. At least as far as you have described here.
In this architecture, you are not employing the outcome of fork() properly. When the return from fork() is zero, you are the child process, and so from there you follow logic which will execute the intended child actions. You're not checking for that.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.