Download File
Download File
Download File
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Subject: NETWORK PROGRAMMING LAB Year : 2010<br />
Class : IV B-Tech C.S.E Semester: First<br />
WEEK 4:<br />
Aim: Write a program to create an integer variable using shared memory concept and<br />
increment the variable simultaniously two processes. Use semaphores to avoid race<br />
conditions. /*file name sem.c */<br />
#include <br />
#include <br />
#include <br />
#include <br />
#include <br />
#include <br />
#include <br />
#include <br />
#include <br />
#include <br />
#include <br />
# include <br />
#define SHMSZ 4 /* Good for integer */<br />
#define BUF_SZ 16<br />
#define SHM_KEY 1234<br />
#define SEM_KEY 1235<br />
#define CHILD_INCREMENT_COUNT 67787<br />
#define PARENT_INCREMENT_COUNT 84823<br />
union semun<br />
{<br />
int val; /* value for SETVAL */<br />
struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */<br />
unsigned short *array; /* array for GETALL, SETALL */<br />
/* Linux specific part: */<br />
struct seminfo *__buf; /* buffer for IPC_INFO */<br />
};<br />
NP Lab Manual , RNEC page: 18