# include <sys/types.h>
# include <sys/ipc.h>
# include <sys/shm.h>
# include <sys/sem.h>
int processfork(int x)
{
int j;
for(j=1;j<x;j++)
{
if(fork()==0)
return j;
}
return 0;
}
void processjoin(int x,int id)
{
int i;
if(id==0)
{
for(i=1;i<x;i++)
{
wait(0);
}
}
else
{
exit(0);
}
}
void lockinit(int *lock1)
{
union semun
{
int val;
struct semid_ds *x;
ushort *y;
}arg;
int j;
j=semget(IPC_PRIVATE,1,0666|IPC_CREAT);
*lock1=j;
arg.val=1;
semctl(*lock1,0,SETVAL,arg);
// printf("After lockinit\n");
}
void locksem(int *lock1)
{
struct sembuf oper;
oper.sem_num=0;
oper.sem_op=-1;
oper.sem_flg=0;
// printf("before Locking\n");
semop(*lock1,&oper,1);
}
void unlock(int *lock1)
{
struct sembuf oper;
oper.sem_num=0;
oper.sem_op=1;
oper.sem_flg=0;
semop(*lock1,&oper,1);
}
void freesharedmem(int shmid)
{
struct shmid_ds *buf;
shmctl(shmid,IPC_RMID,buf);
}
void freesemaphore(int semid)
{
semctl(semid,0,IPC_RMID,0);
}