Problem with read & write


 
Thread Tools Search this Thread
Top Forums Programming Problem with read & write
Prev   Next
# 1  
Old 08-30-2006
Problem with read & write

Hello mates:

I met problem with using read() & write(). I m trying to use read twice on client first time is the size of buffer, 2nd time is the buffer. I think I have to, coz I dnot know file size. So, I write twice on server as well -- 1st, filesize; 2nd, buffer.

The problem is, sometimes, I cannot get anything at 2nd time. The file I got is empty, nothing. However, if I put a sleep(1) before the 2nd write() on server, I can read( but this sometimes may cause a segmentation fault)...

i.e.:
Client Server

read() 1st write() 1st <-----both OK

(if I put a sleep(1)here, it's OK)

read() 2d write() 2nd <-----problem


Does anybody know the reason?

BEST REGARDS,

Elton
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

MAN and read & write function

How to use MAN to find information about read() and write() function ? The command "man read" show some rubbish, for example "man open" show great information about function I need. (2 Replies)
Discussion started by: bbqtoss
2 Replies

2. Programming

help: problem with sockets write/read

I am trying to make a server and client, the client will choose between some options and the server will react accordingly. After a some reads and writes that work the server needs to read from client an INT i use this: read(newSd,&k,sizeof(int));But even if all the other times there was no... (1 Reply)
Discussion started by: theSling
1 Replies

3. IP Networking

read/write,write/write lock with smbclient fails

Hi, We have smb client running on two of the linux boxes and smb server on another linux system. During a backup operation which uses smb, read of a file was allowed while write to the same file was going on.Also simultaneous writes to the same file were allowed.Following are the settings in the... (1 Reply)
Discussion started by: swatidas11
1 Replies

4. Shell Programming and Scripting

PHP read large string & split in multidimensional arrays & assign fieldnames & write into MYSQL

Hi, I hope the title does not scare people to look into this thread but it describes roughly what I'm trying to do. I need a solution in PHP. I'm a programming beginner, so it might be that the approach to solve this, might be easier to solve with an other approach of someone else, so if you... (0 Replies)
Discussion started by: lowmaster
0 Replies

5. Shell Programming and Scripting

Bash Script to Read & Write on different directories

Hi, root@server] df -h 121G 14G 101G 12% /home 147G 126G 14G 91% /backup We having our site files and images are storing in /backup/home/user/files/ through symbolic link created in /home directory pointing in /backup directory as following. root@server] cd /home... (1 Reply)
Discussion started by: mirfan
1 Replies

6. UNIX for Dummies Questions & Answers

About read,write & execute permissons of a directory

Hi all, I want to know differences between read,write & execute permissons given to directory. Thanx in advance. (6 Replies)
Discussion started by: vishwasrao
6 Replies

7. UNIX for Dummies Questions & Answers

user & group read/write access question

folks; I created a new users on my SUSE box and i need to give this user/group a read write access to one specific folder. here's the details: - I created new user "funny" under group "users". - I need to give this user "funny" a read/write access to another directory that is owned by "root".... (3 Replies)
Discussion started by: Katkota
3 Replies

8. Shell Programming and Scripting

File read & execute problem

Hi folks, Need your help. I am writing a KSH script to read a few commands from a file & execute. I am using the following code to read the file line by line & excute each command. When I am printing each line I see it is printing properly but while excuting, the particular "ps" command... (5 Replies)
Discussion started by: tipsy
5 Replies

9. UNIX for Dummies Questions & Answers

How do i access (mount, read & write) a floppy disk from the console, not being root?

welll, the title quite explains what i want to do thanks for your time! (4 Replies)
Discussion started by: kfaday
4 Replies

10. Programming

read, write & STDOUT_FILENO....

hi guys, I'have a question 4 u. Why this code give me the right output (an integer on the stdout): read(fd,&mpid,sizeof(pid_t)); printf("%d\n",mpid); Instead this code give me only a blank line: read(fd,&mpid,sizeof(pid_t)); write(STDOUT_FILENO,&mpid,sizeof(pid_t)); ... (2 Replies)
Discussion started by: M3xican
2 Replies
Login or Register to Ask a Question
pthread_rwlock_trywrlock(3)				     Library Functions Manual				       pthread_rwlock_trywrlock(3)

NAME
pthread_rwlock_trywrlock - Attempts to acquire a read-write lock for write access without waiting. LIBRARY
DECthreads POSIX 1003.1c Library (libpthread.so) SYNOPSIS
#include <pthread.h> int pthread_rwlock_trywrlock( pthread_rwlock_t *rwlock); PARAMETERS
Address of the read-write lock object to acquire for write access. DESCRIPTION
This routine attempts to acquire the read-write lock referenced by rwlock for write access. If any thread already holds that lock for write access or read access, this routine fails and returns [EBUSY] and the calling thread does not wait for the lock to become available. Results are undefined if the calling thread holds the read-write lock (whether for read or write access) at the time this routine is called. If the read-write lock object referenced by rwlock is not initialized, the results of calling this routine are undefined. Realtime applications can encounter priority inversion when using read-write locks. The problem occurs when a high-priority thread acquires a read-write lock that is about to be unlocked (that is, posted) by a low-priority thread, but the low-priority thread is preempted by a medium-priority thread. This scenario leads to priority inversion in that a high-priority thread is blocked by lower-priority threads for an unlimited period of time. During system design, realtime programmers must take into account the possibility of priority inversion and can deal with it in a number of ways, such as by having critical sections that are guarded by read-write locks execute at a high priority, so that a thread cannot be preempted while executing in its critical section. RETURN VALUES
If an error condition occurs, this routine returns an integer value indicating the type of error. Possible return values are as follows: Successful completion. The read-write lock could not be acquired for write access because it was already locked for write access or for read access. The value specified by rwlock does not refer to an initialized read-write lock object. The current thread already owns the read-write lock for write or read access. ERRORS
None RELATED INFORMATION
Functions: pthread_rwlock_init(3), pthread_rwlockattr_init(3), pthread_rwlock_rdlock(3), pthread_rwlock_wrlock(3), pthread_rwlock_unlock(3) Manuals: Guide to DECthreads and Programmer's Guide delim off pthread_rwlock_trywrlock(3)