IPC with PIPE


 
Thread Tools Search this Thread
Top Forums Programming IPC with PIPE
# 1  
Old 04-11-2009
IPC with PIPE-- Help

Hi guys, I'm new to Linux and Unix I have just simple code . But I don't know why it doesn't work ..
Quote:

The idea is:
Parent process: read each character from input file.. then write each of them to pipe
Child Process: read each character from pipe.. then encrypt it.. then write each of them to outputfile..


Void doParent()
{
if(fin!=NULL)
{
char c[2];
c[0]=fgetc(fin) // Get first charater from inputfile


while(c[0]!=EOF)
{
write(fd[1],c,2); // write to pipe
c[0]=fgetc(fin); // get each character from inputfile
};



fclose(fin); // close file
}
}



void DoChild()
{
char c[2];
read(fd[0],c,2); //


while(c[0]!=EOF)
{
char kitu=ceasarEncrypt(c[0]); // Encrypt each character

fputc((char ) kitu,fout); // put each encrypted character to outputfile..
read(fd[0],c,2);
};
fclose(fout);

}
But, the outputfile is Blank.. I don't understand why.. Please help me.. Thank you very much

P.S: sorry, I don't know how to edit this post clearly.. it's hard to read.. Please try..

Last edited by thanh_sam_khac; 04-11-2009 at 02:45 PM..
# 2  
Old 04-11-2009
I try to change the code from while(..) to do{.. } while(..) .. it works..

do
{
c[0]=fgetc(fin); // get each character from inputfile
write(fd[1],c,2); // write to pipe

}
while(c[0]!=EOF)



and it's work.. but wrong result.. Because the last c[0] = EOF, it is written to pipe, then while loop check the codition.. ( wrong ofcourse)..
I include if statement like this:

if(c[0]!= EOF)
{
c[0]=fgetc(fin);// get each character from inputfile
write(fd[1],c,2); // write to pipe

}


Problem again.. The output is blank.. so crazy.. please help me..
# 3  
Old 04-12-2009
anyone, help me..
If you don't understand what I post.. ( my English is not good).. please ask me.. thank you..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to ignore Pipe in Pipe delimited file?

Hi guys, I need to know how i can ignore Pipe '|' if Pipe is coming as a column in Pipe delimited file for eg: file 1: xx|yy|"xyz|zzz"|zzz|12... using below awk command awk 'BEGIN {FS=OFS="|" } print $3 i would get xyz But i want as : xyz|zzz to consider as whole column... (13 Replies)
Discussion started by: rohit_shinez
13 Replies

2. Programming

Problems with pipe IPC

I'm currently studying IPC, I have a first program A: Do an exec for B and wait B: Receive through a fifo a string from a third program "C" and have to resend it to A I was thinking to open a pipe in A before the exec, then passing fd to B as an argument if(pipe(fd)==-1){ ... (1 Reply)
Discussion started by: cifz
1 Replies

3. HP-UX

IPC settings on HP-UX

Hi Experts, Need your help for checking te interprocess communications settings on HP-UX box. Using ipcs command I am able to view Message queue,semapohores etc, but from that output I m not able to understand how to determine if there is any issue with ipc settings and how to resolve that? (1 Reply)
Discussion started by: sai_2507
1 Replies

4. Programming

Best IPC mechanism to be used

Suppose I have 5 independent process divided in two imaginay sets: set1 set2 --------------------- p1 p3 | | p2 p4 | p5 The processes inside each set communicate mutually quite often. I mean p1 and p2 communicate mutually quite often Similarly p3, p4 and p5 communicate mutually... (2 Replies)
Discussion started by: rupeshkp728
2 Replies

5. Shell Programming and Scripting

Replace pipe with Broken Pipe

Hi All , Is there any way to replace the pipe ( | ) with the broken pipe (0xA6) in unix (1 Reply)
Discussion started by: saj
1 Replies

6. Programming

IPC Mechanisms

Hi! I wanted to know the advantages / disadvantages of different IPC mechanims such as sockets, pipes (unnamed) , shared memory & message queues. Pipes for example i hear are fast , but are difficult to debug as compared to sockets. Can you guys please name some situations where one is... (4 Replies)
Discussion started by: _korg
4 Replies

7. Solaris

errors on Netra-440: "IPC Warning: ipc: tcp_protocol: bad magic number"

I was asked to look into a problem with a Sun Netra 440 in another department. On the server in question, the relevant 'uname -a' information is, "SunOS host1 5.9 Generic_118558-16 sun4u sparc SUNW,Netra-440". That information aside, while the other admin is logged into the ALOM, these errors are... (0 Replies)
Discussion started by: Borealis
0 Replies

8. Programming

IPC using named pipe

Hi All, I am facing a vague issue while trying to make two process talk to each other using named pipe. read process ========= The process which reads, basically creates FIFO using mkfifo - ret_val = mkfifo(HALF_DUPLEX, 0666) func. It then opens the pipe using open func - fd = open... (2 Replies)
Discussion started by: sharanbr
2 Replies

9. UNIX for Advanced & Expert Users

IPC using named pipe

Hi All, I am facing a vague issue while trying to make two process talk to each other using named pipe. read process ========= The process which reads, basically creates FIFO using mkfifo - ret_val = mkfifo(HALF_DUPLEX, 0666);) func. It then opens the pipe using open func - fd =... (1 Reply)
Discussion started by: sharanbr
1 Replies

10. UNIX for Dummies Questions & Answers

Ipc

I have a parent that is passing data to child A and then child A has to process it and pass to child B. I am able to pass the data to child A but am not able to pass it to child B. Child B seems to only be receiving the last data instead of the whole data. I saw one example in a book but it uses... (1 Reply)
Discussion started by: scmay
1 Replies
Login or Register to Ask a Question