Created
April 16, 2010 03:04
-
-
Save BH1SCW/367955 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/***** testwrite.c *******/ | |
#include <string.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/ipc.h> | |
#include <sys/shm.h> | |
#include <sys/types.h> | |
#include <unistd.h> | |
#include <sys/time.h> | |
#include <fcntl.h> | |
double my_get_time() { | |
struct timeval tv; | |
gettimeofday(&tv,NULL); | |
return ((double)tv.tv_sec+(double)tv.tv_usec/1000000); | |
} | |
int main(int argc, char** argv) | |
{ | |
int shm_id,i; | |
key_t key; | |
char temp; | |
char *p_map; | |
shm_id=shmget(1234567,100,IPC_CREAT|0660); | |
if(shm_id==-1) | |
{ | |
perror("shmget error"); | |
return; | |
} | |
p_map=(char*)shmat(shm_id,NULL,0); | |
temp='a'; | |
double time_start,time_end; | |
int fd = open("status",O_CREAT|O_RDONLY); | |
for(i = 0;i<2;i++) | |
{ | |
time_start = my_get_time(); | |
flock(fd,LOCK_EX); | |
memset(p_map,temp,1); | |
flock(fd,LOCK_UN); | |
time_end = my_get_time(); | |
printf("%f\n",(time_end-time_start)); | |
} | |
if(shmdt(p_map)==-1) | |
perror(" detach error "); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment