#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
int semWait(int sem,int n)
{
struct sembuf sem_op;
sem_op.sem_num = 0;
sem_op.sem_op = n;
sem_op.sem_flg = 0;
return semop(sem,&sem_op,1);
}
int main(int argc, char **argv)
{
pid_t pid;
int sem_id;
key_t key;
int fd;
/* Создаем новый семафор */
if((sem_id =
semget(IPC_PRIVATE,1,IPC_CREAT|IPC_EXCL|S_IRUSR|S_IWUSR)) == -1)
perror("Can't creat semafor"),exit(1);
if((pid = fork()) == 0)
{
while(1)
{
printf("Потомок\n");
}
} else {
while(2)
{
printf("Родитель\n");
}
}
if((semctl(sem_id,1,IPC_RMID)) == -1)
perror("semctl");
exit(0);
}
Помогите синхронизировать родителя(родитель выпо-ся первым) с сыном, нужно это сделать с помощью семафоров. Семафоры начал только изучать. Зарание спасибо!