LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Send input to child process (https://www.linuxquestions.org/questions/linux-software-2/send-input-to-child-process-526523/)

cdog 02-07-2007 04:45 PM

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.

wjevans_7d1@yahoo.co 02-07-2007 05:22 PM

Type the following command:

man socketpair

Then experiment with it and have fun! Your class sounds great!

studioj 02-07-2007 06:37 PM

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

cdog 02-07-2007 08:24 PM

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?

studioj 02-07-2007 09:26 PM

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.

manish.ym 02-07-2007 10:00 PM

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


All times are GMT -5. The time now is 05:41 AM.