read system call reading the same data


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users read system call reading the same data
# 1  
Old 12-13-2009
read system call reading the same data

Hi,
I wrote a program, to read from a master terminal.
However, the 'read' system call keeps returning the same data endlessly (I expected it to read once and then block).
What will cause t data to be flushed, after 1 read?

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <fcntl.h>

int main()
{
int fd, cfd;
char *path;
char s[20];

memset(s, 0, 20);

fd = open("/dev/ptmx", O_RDWR);

printf("fd is %d\n", fd);

grantpt(fd);
unlockpt(fd);

path = ptsname(fd);

while(read(fd, s, 19)) /* this 'read' reads t same data again n again. I expect it to block after 1 read */
{
printf("Read %d:%s\n", strlen(s), s);
}

return (0);
}

---------- Post updated at 08:19 PM ---------- Previous update was at 08:13 PM ----------

n just to add, i do
echo > /dev/pts/X,
where X corresponds to the slave pts.

its after this that t read goes on infinitely.

---------- Post updated at 09:14 PM ---------- Previous update was at 08:19 PM ----------

sorry guys......... a stupid mistake of not reading t output from 'read' :P
# 2  
Old 12-14-2009
Your read() call probably returned -1 and didn't modify the contents of the buffer.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To call Oracle procedure by reading parameter file in UNIX

hi Guys, is there a way to pass parameter into oracle store procedure by reading date range in file and increment accordingly. Something like this file.txt 01-JAN-2015 03-JAN-2015 sqlplus -s user/pwd@DB execute TEST( to_date( '01-JAN-2015, 'dd.mm.yyyy' ), to_date( '03-JAN-2015', ... (1 Reply)
Discussion started by: rohit_shinez
1 Replies

2. UNIX for Dummies Questions & Answers

When reading a csv file, counter to read 20 lines and wait for minute then read next 20 till end

Hello All, i am a newbie and need some help when reading a csv file in a bourne shell script. I want to read 10 lines, then wait for a minute and then do a reading of another 10 lines and so on in the same way. I want to do this till the end of file. Any inputs are appreciated ... (3 Replies)
Discussion started by: victor.s
3 Replies

3. UNIX for Advanced & Expert Users

Problem in read() system call in Xenomai-2.4

Dear All, I am having problem with read() system call in Blocking Mode. In my driver interrupt intimation done through RT FIFO. so i have created the RT FIFO and open the FIFO using open() system call with O_RDONLY flag and i am waiting for interrupt using read() blocking call.initally... (1 Reply)
Discussion started by: rajamohan
1 Replies

4. SCO

file system not getting mounted in read write mode after system power failure

After System power get failed File system is not getting mounted in read- write mode (1 Reply)
Discussion started by: gtkpmbpl
1 Replies

5. Linux

Read data of a page frame (linux) make freeze the system

Hello, I'm writing a linux driver that reading the data of a page frame of an process. But when I use it, it make immediately freeze the system. Can you help me? Thank for reading my question! system: Ubuntu 9.04, kernel 2.6.28.15, Intel Duo static int read_addr(int pid, unsigned long... (2 Replies)
Discussion started by: hahai
2 Replies

6. Programming

C:system call

Hi I'm studing the system call. I've written a small program that return the time spent in doing some operations. Now I'd like to write one that return the time spent in user mode of a process. I'm reading that i should use the tms struct: clock_t times(struct tms *buf); struct tms {... (2 Replies)
Discussion started by: Dedalus
2 Replies

7. Programming

reading reading data from webpage

hi iam reading data from web page using request socket and curl socket. now my problem is some the web page containg data as a image so how can i read the data from a image. thank,inadvance. sree (3 Replies)
Discussion started by: phani_sree
3 Replies

8. UNIX for Advanced & Expert Users

how to differentiate system call from library call

Hi, Ho do I differentiate system call from library call? for example if I am using chmod , how do I find out if it is a system call or library call? Thanks Muru (2 Replies)
Discussion started by: muru
2 Replies

9. Shell Programming and Scripting

Using loop reading a file,retrieving data from data base.

Hi All, I am having trouble through, I am reading the input from tab delimited file containing several records, e.g. line1 field1 field2 field3 so on.. line2 field1 field2 field3 so on.. .. .. on the basis of certain fields for each record in input file, I have to retrieve... (1 Reply)
Discussion started by: Sonu4lov
1 Replies

10. Programming

read system call

When i read 4 bytes from a socket the read function returns 0 value. what does it mean? How should i know whether a message is available in the socket or not? (1 Reply)
Discussion started by: Madhu Babu
1 Replies
Login or Register to Ask a Question