![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can a child process return a specific value to a parent process ? | Ametis1970 | High Level Programming | 8 | 04-09-2008 08:22 PM |
| Parent child Relation !! using awk/sed ??? | varungupta | UNIX for Advanced & Expert Users | 0 | 01-29-2008 11:24 AM |
| Implementing 2 pipes between a parent and child process | bwgoudey | High Level Programming | 2 | 09-24-2005 08:14 PM |
| parent and child process question? | tosa | High Level Programming | 0 | 02-16-2005 12:04 PM |
| kill parent and child | larry | UNIX for Dummies Questions & Answers | 4 | 01-11-2003 09:18 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
display in a child process a command called in the parent one
Hi , Could you tell me if I am right
1. Using fork(), pipe(), execlp() and dup() (see man 2 dup), write a C program executing the command ps -j in a parent process, displaying the result in a child process. PHP Code:
Can't we make this operation just using the pipe itself at 100%? Thank you very much. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Quote:
Not all the dups are necessary, the parent can just read directly from the reading end of the pipe. But the child process, /bin/ps, doesn't know or care that you have a pipe open -- it writes to standard output, no ifs, ands, or buts. The only way to tell it to write to your pipe, is to make it's standard output the pipe. |
|
#3
|
||||
|
||||
|
Quote:
|
|
#4
|
|||
|
|||
|
I would check out the freopen function. I think you can place it just before your exec() call and the new process would inherit the open file descriptors ( someone correct me if I'm wrong ).
Code:
NAME
fopen, fdopen, freopen - stream open functions
SYNOPSIS
#include <stdio.h>
FILE *fopen(const char *path, const char *mode);
FILE *fdopen(int fildes, const char *mode);
FILE *freopen(const char *path, const char *mode, FILE *stream);
DESCRIPTION
...
The freopen function opens the file whose name is the string pointed to by path and
associates the stream pointed to by stream with it. The original stream (if it
exists) is closed. The mode argument is used just as in the fopen function. The
primary use of the freopen function is to change the file associated with a stan-
dard text stream (stderr, stdin, or stdout).
|
|
#5
|
|||
|
|||
|
Quote:
|
|
#6
|
|||
|
|||
|
Quote:
|
|
#7
|
||||
|
||||
|
My apology for this wasteful post..
|
||||
| Google The UNIX and Linux Forums |
| Thread Tools | |
| Display Modes | |
|
|