This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin 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
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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: 62887
203
  • 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.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!