blob: 6d19bdad7c1d77f4802f1050314914ad6b0f27d9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#include <unistd.h>
#include <stdio.h>
#include <semaphore.h>
#include <sys/stat.h>
#include <fcntl.h>
int main() {
sem_t* sem1 = sem_open("/sem1", O_CREAT, 0755, 0);
sem_t* sem2 = sem_open("/sem2", O_CREAT, 0755, 0);
int fd = open("test.txt", O_WRONLY | O_CREAT, 0755);
while (1) {
sem_wait(sem2);
lseek(fd, 0, SEEK_END);
write(fd, "[2]", 3);
printf("written\n");
sem_post(sem1);
}
close(fd);
sem_close(sem1);
sem_close(sem2);
sem_unlink("/sem2");
return 0;
}
|