LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-30-2015, 04:04 PM   #16
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930

There are not 3 children the way that's written.

For now do not close any descriptors, leave them open. Exiting processes will close descriptors as needed. There is no purpose to closing descriptors, nor using dup(). Rather than be complicated, leave those things alone, so you can print out stuff and aid in your programming debug. I also recommend each time you print something you prepend any print statements similar to: "child1: pid(xxx) your comments" because all printf's will go to the standard console.

Use and touch pipe1 in child1 only. Do not touch any other pipes from withing child1
Same applies in sequence for pipe2/child2 and (not yet coded) pipe3/child3.

Remember that the child process is a copy of the parent at the time it was forked, thus it knows the about the relevant pipe. Still I would not bother closing irrelevant pipes, I'm the sort who feels that stuff gets cleaned up when you exit the process and also you try to do all that cleanup at the start and you may inadvertently close the incorrect resource, so for now don't do that.

Use waitpid() not wait. You can use W_NOHANG (validate my spelling there because I didn't look it up) and do so from within a loop where the exit conditions for the loop are that you've received exit signals from all children.

Why are you using pipes here? You're not doing anything with them. Yet? ...
 
Old 10-30-2015, 06:16 PM   #17
ash2006
LQ Newbie
 
Registered: Oct 2015
Posts: 4

Rep: Reputation: Disabled
Number of active processes

ps -A | wc -l displays the number of processes. so i need to pass the output of ps -A to the second child. And finally i need the redirect standard output using dup or dup2 to the pipe and in the parent process, read from the pipe.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting pid of a process!! vishamr2000 Programming 34 03-12-2015 07:12 AM
Start a Process with dedicated PID murder Linux - Newbie 5 08-15-2005 03:49 PM
how to get more process' info according to its PID? iclinux Programming 1 02-05-2005 05:30 AM
ps showing duplicate process same PID dooahhdoo Red Hat 0 07-09-2004 05:52 AM
Get Next PID of Process Tree zer0python Programming 7 11-26-2003 11:56 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration