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.
This program creates a circular queue of integers of size 20 in shared memory. It then creates 4 child processes. The second, third, and the fourth process created enters 50 consecutive integers each starting from 100, 200, and 300 respectively (so the second process enters 100, 101, 102,…,149; the third process enters 200, 201, 202, ..249 and so on). The first process sums up the integers entered and prints the final sum after all the integers have been entered and summed up.
The parent process waits until all child processes finish, cleans up all the shared memory and semaphore created, and exits.
HOWEVER, the program is not behaving in the expected manner..... the problem arises when the queue becomes full..
CAN ANYONE HELP ME OUT?... its urgent !!
this question looks an awful lot like homework. lpease note that it is against LQ rules to request help for homework, and if this is indeed some sort of assignment / coursework i'd be grateful if you could remove the content yourself.
this is not a homework but a program that i encountered myself during learning semaphores and shared memory....... i have written the whole code myself but i m puzzled to see that its not working.so thats y I'd b grateful if any one of u can plz have a look and point out the problem....
I'd recommend starting smaller. Maybe just 1 child. See if simplifying the problem leads you to a solution. If you can get it to work with 1 child, then try 2 children before jumping to 5.
i have worked successfully with 1 and 2 child processes......... in this program, the queue takes input perfectly for first 20 entries but after that instead of emptying the queue, the program goes to child2 and then the problem starts....data are taken in random order from the children after 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.