Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I understand the fork concept. I'm trying to solve the following problem.

I have to write a program that forks. The parent process gets a valid Unix command from the user, and passes it to the child. The child executes the given command, returning the results to the parent, which displays them.

explain any example of the program?

   ./a.out ls 

   parent : get command name - ls
  child  : execute that command not display
  parent : display the command result

             file1 file2 file3

            (Or)  (If you are not understand)

Design this architecture                               

parent                                              

 INPUT         
 DISPLAY
 -----------

  CHILD
  PROCESS     EXECUTE                                                                            -------------                                       

Where

      INPUT - Get the input from the user which could be a valid unix  command
    EXECUTE   - Execute the given command

    DISPLAY - Display the result of the command.
share|improve this question
fork() creates a new process by duplicating the calling process.And because fork() get void type argument, you can't get pid of any program. Where did you see same example? – Mohsen Pahlevanzadeh Feb 2 at 11:54
1  
@Mohsen, what makes you think fork() is void? It returns the PID of the child to the parent, and 0 to the child. – alexis Feb 2 at 12:37
1  
A common arrangement is to open a pipe, then close the reading end in the child, and the writing end in the parent. In fact, it is so common that we strongly suspect that you have not done any googling at all. What have you tried? – tripleee Feb 2 at 12:51
its possible. The fork create the one child is if(pid>0) is the parent get the name of the command and the child execute the process if (pid==0) then print ("/bin/argv[i]") not display it return the parent and parent display the command . but I don't know how to write the code – loganaayahee Feb 2 at 12:55
@alexis fork() doesn't get argument , i didn't tell it return void type. please reread my comment. – Mohsen Pahlevanzadeh Feb 2 at 21:03
show 2 more comments

closed as not a real question by Mat, rahmu, warl0ck, manatwork, Renan Feb 2 at 13:47

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

Browse other questions tagged or ask your own question.