осуществляется работа с одним и тем же файлом. Каждый процесс открывает файл, Один процесс пишет в файл, другой - читает из него.
нужно сделать с блокировками, но никак не получается
int main()
{
int fd;
int fd_1;
int ret_status;
char buffy[128];
char buffy1[32];
sprintf(buffy, "Hello World");
struct flock fl;
fl.l_type = F_WRLCK; /* F_RDLCK, F_WRLCK, F_UNLCK */
fl.l_whence = SEEK_SET; /* SEEK_SET, SEEK_CUR, SEEK_END */
fl.l_start = 0; /* Offset from l_whence */
fl.l_len = 0; /* length, 0 = to EOF */
fl.l_pid = getpid(); /* our PID */
if (access("tel_position", F_OK) == 0) {
fd = open("tel_position",O_RDWR|O_TRUNC);}
else {
fd = creat("tel_position",S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);}
fd_1 = open("tel_position",O_RDONLY); /* get the file descriptor */
fork();
ret_status = fcntl(fd, F_SETLKW, &fl);
write(fd,buffy,strlen(buffy));
// sleep(5);
fl.l_type = F_UNLCK;
fcntl(fd, F_SETLK, &fl); /* set the region to unlocked */
close(fd);
fcntl(fd_1, F_SETLKW, &fl);
while (read(fd_1, buffy1, 32) > 0){
fl.l_type = F_UNLCK; /* tell it to unlock the region */
fcntl(fd_1, F_SETLK, &fl); /* set the region to unlocked */
close(fd_1);
//sscanf (buffy1,"%s" );
printf("telescope position:", buffy1);}
}