简体   繁体   中英

How to Approach File I/O with C System Calls and Pipes?

First off, apologies in advance for any sloppy code - I'm relatively new to C. I'm currently working my way through some coding for my introductory OS class, but having spent far too many hours of my weekend trying to brute-force my way through this one problem, I figure it's time I swallow my pride and try to get a nudge in the right direction here. It deals with compressing basic text files and is meant to make use of Unix system calls and pipes. Following a fork() call, one process is supposed to handle reading a text file (specified as a command line argument) and then send the data via pipe to the other process, which handles compression and writing to a destination file. Having tested out a non-pipe version of this program, I'm fairly sure the compression stuff works as intended, but I think my issue lies with the pipe data sharing. I don't think anything is getting passed through, based on some amateur debugging.

The program also terminates prematurely with the following line:

Segmentation fault (core dumped)

And here's the code itself:

(redacted)

Can someone figure out what the issue may be? I'd be unbelievably appreciative.

Create the pipe before you fork. As it is you are creating a seperate pipe in each process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM