c - Put variables in a buffer in different parts of the program -
i'm working on c project requires me send variables on file through socket connection (on same machine - through "localhost"). therefore, in order send variables file file b, put such variables in buffer (defined char 1d array) , send whole buffer different variables contained in it. so, use sprintf(buffer, "%f\n %f\n", variable1, variable2) put variables file a. file b read buffer, , associate variables in buffer variables of it's own, do: sscanf(buffer, "%f\n %f\n, &variable1, &variable2); variable1 , variable2 have been defined in file b.
however, i'm wondering if it's possible put variables in buffer in file through different instances in program. if so, everytime new variable put in buffer, file b able access variables in same order they're put in file a? example, if variable1 , variabe2 put in buffer in point a, , varibale 3 put in buffer in point b, file b able access variables in order?
finally, if variable of same name put in buffer in 2 different locations, second time overwrite first? i.e, if variable1 put in buffer in point x , again in point y, second time variable put in point y overwrite time put in point x?
i'm not sure if question clear enough hope , appreciate help!
it looks can solve problem using standard unix ipc mechanisms. don't give many concrete details on want achieve seems try like:
- make semaphore (named or not) processes share
- look
sem_open
- look
- make data structure - maybe queue - lives in shared memory
- look
shm_open
,mmap
- look
- all operations on queue should protected semaphore
- for example
add
queue should protectedsem_wait
/sem_post
block
- for example
Comments
Post a Comment