LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-07-2007, 04:45 PM   #1
cdog
Member
 
Registered: Dec 2005
Posts: 65

Rep: Reputation: 15
Send input to child process


I have a linux school assignment. I have to write a program in C that scans a directory and sends all the files with certain extentions to the child process that does all the job. I managed to open and read the directory using the functions opendir and readdir, but I don't know how to send them to the child. I need some ideas.
 
Old 02-07-2007, 05:22 PM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
Type the following command:

man socketpair

Then experiment with it and have fun! Your class sounds great!
 
Old 02-07-2007, 06:37 PM   #3
studioj
Member
 
Registered: Oct 2006
Posts: 460

Rep: Reputation: 31
just to get you started
Code:
int pipe_file_descriptors[2];
pid_t pid;
pipe(pipe_file_descriptors);
pid=fork();
now if im in the child process close the write end of the pipe
convert the read end into a FILE object
read from it
if im in the parent close the read end of the pipe
blah blah same thing but backwards
 
Old 02-07-2007, 08:24 PM   #4
cdog
Member
 
Registered: Dec 2005
Posts: 65

Original Poster
Rep: Reputation: 15
Is there a way to use popen because I know this command? Also, on files with specific extensions the child process should run different functions. How am I going to do this? Thanks?
 
Old 02-07-2007, 09:26 PM   #5
studioj
Member
 
Registered: Oct 2006
Posts: 460

Rep: Reputation: 31
when you use popen the child process is a shell command so thats not what you want at all.
as far as extensions -- (not something usually done in Linux)
you just look at the filename string and decide if it has the extension you are looking for.

we shouldn't give you more yet so you can try yourself.
you post code later if you get stuck and we can help a little more.
if we give it to you you won't learn.
programming is all about knowing you can figure it out.
not many of us know ahead of time how to do stuff til we are in the middle of it and figure it out.
 
Old 02-07-2007, 10:00 PM   #6
manish.ym
LQ Newbie
 
Registered: Feb 2007
Distribution: Fedora Core 6
Posts: 6

Rep: Reputation: 0
see man pages for
pipe, fork, and if you want to dup and dup2 also,
Manish YM
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how a father process know which child process send the signal SIGCHLD icoming Programming 10 07-20-2010 07:26 AM
How to kill a Child and all its subsequent child process in C shayer009 Programming 3 12-04-2007 12:40 AM
child process usses same amount of ram as parent process socialjazz Programming 7 10-19-2006 05:48 PM
How to send CTRL-D to child process via a pipe? neo_in_matrix Programming 10 09-15-2005 07:09 PM
Killing a child process from another child marri Programming 6 10-01-2004 07:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:20 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