Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

popen() simulation C program  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !!! I have a difficulty with a recent task. I have a very little programming experience and although I do not want someone to solve my homework but the code I wrote looks bad and doesn't work.
I understand how each function work s but have a major difficulty compose them together to a functioning code.
So I would be very thankful if someone who understands C could take a look at the task. Here it is:

  I have to write popen() and pclose() functions following the steps: creating a pipe (with pipe(2)) and a child process (with fork(2)). Then associate child process one end of the pipe ("r" or "w") with stdin or stdout, respectively, (with dup2(2)). Afterwards the child process executes the specified command (with execl(3) or execv(3)). Use the shell (sh(1)) similar to the original popen(3) to execute that command. At last the main function has to construct a FILE * from a filedescriptor of the pipe using the fdopen(3) library function.

On pclose(), the calling process waits (waitpid(2)) for the termination of the child process. To ease the implementation, it is sufficient to support at most one pipe at a time. Guarantee that a program cannot call popen() two (or more) times without appropriate and sufficient pclose() in between.

Export all necessary entities (e.g., extern declarations of the two functions) in a corresponding header file.
 
Marshal
Posts: 64157
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

We don't provide people with complete solutions; please show us what you have achieved so far.
 
moose poop looks like football shaped elk poop. About the size of this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!