Example #1
0
File: main.c Project: jsno9/public
void funthread1(char *msg)
{
	int val;

	printf("funthread1\n");
	val=pthread_mutex_lock(&mutex);
	if(val!=0)
	{
		printf("lock1 mutex error\n");
	}
	sleep(1);
	val=pthread_mutex_lock(&mutex2);
	if(val!=0)
	{
		printf("lock1 mutex2 error\n");
	}
	g_value=0;
	printf("thread 1 lock,g_value=%d\n",g_value);
	g_value=1;
	printf("thread 1 lock,g_value=%d\n",g_value);
	sleep(2);
	pthread_mutex_unlock(&mutex);
	pthread_mutex_unlock(&mutex2);
	printf("thread 1 unlock\n");
  
}
Example #2
0
void client1()
{
while(1){
  P(p[99].empty);
  int a[10];
  int i=0;
  printf("\nClient 1: Sending \n");
  for(i=0;i<10;i++) { 
  a[i]=i+20;
  printf("%d\t", a[i]); 
  }
  printf("\n");

  send(&p[99], a);
  for(i=0;i<10;i++)
  printf("%d\t", p[99].msgs[p[99].in - 1][i]);
  printf("\n");
  printf("Client 1: Send success\n");
  sleep(5);
  V(p[99].full);
  //yield();
  P(p[20].full);
  int b[10];
  receive(&p[20],b);
  printf("Client 1: Receive \n");
  for(i=0;i<10;i++)
  printf("%d\t", b[i]);
  printf("\nClient 1: Receive success\n");
  sleep(10);
  V(p[20].empty);
  printf("*******************************************************************\n");
}
}
Example #3
0
void commit_options(modbus_param_t * mb_param)
{

	int ret;

	// XXX Redundant? seems to do nothing
	if(debug > 0){
		printf ("\n\nnow forcing the eeprom\n");
	}	       
	ret = force_single_coil(mb_param, SUNSAVERMPPT, FORCE_EEPROM_UPDATE, 1);

	if(debug > 0){
		printf("set returnd %d\n", ret);
	}

	sleep(2); // just to be sure

	if(debug > 0){
		printf ("now forcing the reset. this will NOT return anything!\n");
	}	       
	ret = force_single_coil(mb_param, SUNSAVERMPPT, RESET_CONTROL, 1);
			       
	if(debug > 0){
		printf("set returnd %d\n", ret);
	}

	printf("NOTE: you will need to physically power the unit off by disconnecting the battery, in order for the changes to take effect.\n\nWaiting for unit to reset and communications to return...\n");

	sleep(10);
	
}
task main() {
  // The data to be written: 0x3F = 111111 binary,
  // makes all digital ports outputs.
  HTPBsetupIO(HTPB, 0x3F);

  while(true) {
    // Switch off LED on port B0
    HTPBwriteIO(HTPB, 0x00);
    sleep(30);
    wolight = HTPBreadADC(HTPB, 0, 10);

    // Switch on LED on port B0
    HTPBwriteIO(HTPB, 0x01);
    sleep(30);
    wlight = HTPBreadADC(HTPB, 0, 10);

    // Calculate the difference
    lightdelta = wlight - wolight;

    eraseDisplay();
    displayTextLine(1, "%4d", wlight);
    displayTextLine(2, "%4d", wolight);
    displayTextLine(3, "%4d", lightdelta);
    sleep(30);
  }
}
Example #5
0
void pacmanClear(int cant) {
    int size=1024/4/cant;

    for (int j = 0; j < 760; j+=cant*size) {
        for (int i = 0; i < 1024; i+=size/4) {
                for (int k = 0; k < cant; ++k)
                drawPacman(i+size/2,j+size/2+k*size,size/2,6);
                sleep(100/cant);
                 for (int k = 0; k < cant; ++k)
                drawPacman(i+size/2,j+size/2+k*size,size/2,12);
                sleep(100/cant);
                for (int k = 0; k < cant; ++k)
                drawClosePacman(i+size/2,j+size/2+k*size,size/2);
                sleep(100/cant);
                for (int k = 0; k < cant; ++k)
                drawPacman(i+size/2,j+size/2+k*size,size/2,12);
                sleep(100/cant);
                for (int k = 0; k < cant; ++k)
                drawCSquare(i,j+k*size,size+1,size+1,0);
        }
    }

    clear();



}
task main () {
  displayCenteredTextLine(0, "Mindsensors");
  displayCenteredBigTextLine(1, "TMUX");
  displayCenteredTextLine(3, "SMUX Test");
  displayCenteredTextLine(5, "Connect SMUX to");
  displayCenteredTextLine(6, "S1 and TMUX to");
  displayCenteredTextLine(7, "SMUX Port 1");
  sleep(2000);

  while (true) {
    eraseDisplay();
    displayTextLine(0, "MS Touch MUX");

    // Get the raw data from the sensor, this is not processed
    // by the driver in any way.
    displayTextLine(1, "Raw: %d", 1023 - HTSMUXreadAnalogue(MSTMUX));

    // Go through each possible touch switch attached to the TMUX
    // and display whether or not is active (pressed)
    for (short i = 1; i < 4; i++) {
      if (MSTMUXisActive(MSTMUX, i))
        displayTextLine(i+2, "Touch %d: on", i);
      else
        displayTextLine(i+2, "Touch %d: off", i);
    }

    // Display the binary value of the active touch switches
    // 0 = no touch, 1 = touch 1 active, 2 = touch 2 active, etc.
    // touch 1 + touch 2 active = 1 + 2 = 3.
    displayTextLine(7, "Status: %d", MSTMUXgetActive(MSTMUX));
    sleep(50);
  }
}
Example #7
0
//
// FUNCTION : sleepLockSleepUnlock
// DESCRIPTION :
// This function waits for 2 seconds,
// tries to lock sleepMutex, waits for 2
// seconds, unlocks sleepMutex, and
// then waits at the barrier for
// the other threads to finish.
// PARAMETERS :
// RETURNS :
//
void * sleepTryLockSleepUnlock(void * c) {
	printf("Starting sleepTryLockSleepUnlock\r\n");

	sleep(2);

	printf("sleepTryLockSleepUnlock thread trying to lock mutex\r\n");
	int res = pthread_mutex_trylock(&sleepMutex);

	if (res == EOK) {
		printf("sleepTryLockSleepUnlock locked sleepMutex\r\n");

		sleep(2);

		pthread_mutex_unlock(&sleepMutex);
	}
	else {
		printf("sleepTryLockSleepUnlock couldn't lock sleepMutex\r\n");
	}

	printf("sleepTryLockSleepUnlock waiting at the barrier\r\n");
	pthread_barrier_wait(&sleepBarrier);

	printf("sleepTryLockSleepUnlock ending\r\n");

	return NULL;
}
Example #8
0
static void *do_monitor(void *data)
{
    int result = ERROR_RC;
    char cdr_full_path[256];
    DIR *cdr_dir;
	VALUE_PAIR *resend = NULL;
	struct dirent *dir_s = NULL;
	int count = 0; // times of resend
	int wait_time = 0;
	
	for(;;){
        sleep(1); /* sleep 1 minute */
		/* Open dir */
		if((cdr_dir=opendir(cdr_directory)) == NULL){
			ast_log(LOG_ERROR,"Failed to open %s\n",cdr_directory);
		} else {
		/* open */
			while((dir_s=readdir(cdr_dir))!=NULL) {
				if(!strcmp(dir_s->d_name,".") || !strcmp(dir_s->d_name,".."))
					continue;
				memset(cdr_full_path,0,sizeof(cdr_full_path));
				snprintf(cdr_full_path,sizeof(cdr_full_path),"%s/%s",cdr_directory,dir_s->d_name);
				resend = get_avp(cdr_full_path);
				if(resend){
					result = rc_acct(rh,0,resend);
				}else{
					ast_log(LOG_ERROR, "get avp return null!");
				}
				if(result != OK_RC){
					ast_log(LOG_ERROR, "Failed to re-record Radius CDR record!\n");
					if(resend){
						ast_avpair_free(resend);
						resend = NULL;
					}
					count++;
					wait_time = count * 60; // reterval to resend cdr record: 60s, 120s,180s,240s......
					ast_log(LOG_DEBUG,"----------wait_time:%d-----------\n", wait_time);
					break;
				}else{
				ast_log(LOG_DEBUG,"----------cdr_full_path:%s send OK!-----------\n", cdr_full_path);
				wait_time = 0;
				count = 0;
				if(remove(cdr_full_path) != 0)
					ast_log(LOG_WARNING,"Failed to delete %s\n",cdr_full_path);
			}
			if(resend){
				ast_avpair_free(resend);
				resend = NULL;
			}
		}
		closedir(cdr_dir);
		}
		
		if (wait_time > 0) {
			ast_log(LOG_DEBUG,"if-wait_time>0----------wait_time:%d-----------\n", wait_time);
			sleep(wait_time);
		}
	}
	return NULL;
}
void myproc(){

	//printf(1,"\n%d\n",writeproc("tmp",O_CREATE|O_RDWR));
	
	
		   
			int i=0;
			while(i<2){
				sleep(100);
				printf(1,"%d",i);
				i++;
			}
			

		//sleep(400);
writeproc("tmp",O_CREATE|O_RDWR);
			
			

//readproc("tmp",O_RDONLY);	
			
		
	    while(1){
				sleep(100);
				printf(1,"%d",i);
				i++;
			}
	    

	//readproc("tmp",O_RDONLY);
printf(1,"\n quitting!!!!!!\n");
	exit();
}
Example #10
0
int main()
{
    int value;
  if(map_peripheral(&gpio) == -1) 
  {
    printf("Failed to map the physical GPIO registers into the virtual memory space.\n");
    return -1;
  }
 
  // Define pin 17 as output
  INP_GPIO(2);
  OUT_GPIO(17);
 
  while(1)
  {
    // Toggle pin 17 (blink a led!)
    GPIO_SET = 1 << 17;
    sleep(1);
 
    value = GPIO_READ(2);
    while(!value) {
//        delay(20);
        value = GPIO_READ(2);
    }
    
    GPIO_CLR = 1 << 17;
    sleep(1);
  }
 
  return 0; 
}
Example #11
0
File: critical.c Project: y-c/APUE
int
main(void)
{
	sigset_t	newmask, oldmask, pendmask;

	if (signal(SIGQUIT, sig_quit) == SIG_ERR)
		err_sys("can't catch SIGQUIT");

	/*
	 * Block SIGQUIT and save current signal mask.
	 */
	sigemptyset(&newmask);
	sigaddset(&newmask, SIGQUIT);
	if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
		err_sys("SIG_BLOCK error");

	sleep(5);	/* SIGQUIT here will remain pending */

	if (sigpending(&pendmask) < 0)
		err_sys("sigpending error");
	if (sigismember(&pendmask, SIGQUIT))
		printf("\nSIGQUIT pending\n");

	/*
	 * Reset signal mask which unblocks SIGQUIT.
	 */
	if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
		err_sys("SIG_SETMASK error");
	printf("SIGQUIT unblocked\n");

	sleep(5);	/* SIGQUIT here will terminate with core file */
	exit(0);
}
Example #12
0
int
main(int argc, char **argv)
{
    maestro_t *m;
    char buf[10];

    pi_usb_init();
    if ((m = maestro_new()) == NULL) {
	fprintf(stderr, "couldn't find a recognized device.\n");
	exit(1);
    }

#define GO 100
#define STOP 50.5
    maestro_set_servo_pos(m, 0, 0);
    maestro_set_servo_pos(m, 1, STOP);

    while (true) {
	printf("Hit enter to drop: "); fflush(stdout);
	fgets(buf, sizeof(buf), stdin);
	maestro_set_servo_pos(m, 0, 100);
	printf("Hit enter to retract: "); fflush(stdout);
	fgets(buf, sizeof(buf), stdin);
	maestro_set_servo_pos(m, 0, 0);
	sleep(1);
	maestro_set_servo_pos(m, 1, GO);
	sleep(30);
	maestro_set_servo_pos(m, 1, STOP);
    }

    return 0;
}
Example #13
0
/* create thread */
void *diner(int *i)
{
    int v;
    int eating = 0;
    printf("I'm diner %d\n", *i);
    v = *i;
    while (eating < 5)
    {
        printf("%d is thinking\n", v);
        sleep(v / 2);
        printf("%d is hungry\n", v);

        pthread_mutex_lock(&grab_mutex); /* take the grab fork lock */
        while (num_eating >= EAT)
        {
            pthread_cond_wait(&eat_cond, &grab_mutex); /* wait until allowed to eat */
        }
        pthread_mutex_lock(&fork_mutex[v]); /* take left fork */
        pthread_mutex_lock(&fork_mutex[(v + 1) % NUMP]); /* take right fork */
        pthread_mutex_unlock(&grab_mutex); /* drop the grab fork lock */
        printf("%d is eating\n", v);
        num_eating++;
        eating++;
        sleep(1);
        printf("%d is done eating\n", v);
        pthread_mutex_lock(&drop_mutex); /* take the drop fork lock */
        num_eating--;
        pthread_mutex_unlock(&fork_mutex[v]); /* drop left fork */
        pthread_mutex_unlock(&fork_mutex[(v + 1) % NUMP]); /* drop right fork */
        pthread_cond_broadcast(&eat_cond); /* signal all allowed to eat */
        pthread_mutex_unlock(&drop_mutex); /* drop the drop fork lock */
    }
    pthread_exit(NULL);
}
Example #14
0
main()
{ int pid;

  /* get child process */
  
   if ((pid = fork()) < 0) {
        perror("fork");
        exit(1);
    }
    
   if (pid == 0)
     { /* child */
       signal(SIGHUP,sighup); /* set function calls */
       signal(SIGINT,sigint);
       signal(SIGQUIT, sigquit);
       for(;;); /* loop for ever */
     }
  else /* parent */
     {  /* pid hold id of child */
       printf("\nPARENT: sending SIGHUP\n\n");
       kill(pid,SIGHUP);
       sleep(3); /* pause for 3 secs */
       printf("\nPARENT: sending SIGINT\n\n");
       kill(pid,SIGINT);
       sleep(3); /* pause for 3 secs */
       printf("\nPARENT: sending SIGQUIT\n\n");
       kill(pid,SIGQUIT);
       sleep(3);
     }
}
Example #15
0
int main(int argc, char* argv[])
{
    int rank, size;
    char *rk;

    /* get the MPI rank from the environ */
    if (NULL == (rk = getenv("OMPI_COMM_WORLD_RANK"))) {
        fprintf(stderr, "FAILED TO GET RANK\n");
        exit(1);
    }
    if (1 < argc) {
        /* rank 0 exits first */
        if (0 == strcmp(rk, "0")) {
            exit(1);
        } else {
            sleep(1);
        }
    } else {
        if (0 == strcmp(rk, "0")) {
            sleep(1);
            exit(1);
        }        
    }
    
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);

    printf("Hello, World, I am %d of %d\n", rank, size);

    MPI_Finalize();
    return 0;
}
Example #16
0
main()
{
    int i,fd;
    $DESCRIPTOR(gsdnam1,"gsd3");
    $DESCRIPTOR(gsdnam2,"gsd4");
    struct _va_range range1, range2;
    struct _secid id1, id2;
    range1.va_range$ps_start_va=0x10000000;
    range1.va_range$ps_end_va=0x10008000;
    range2.va_range$ps_start_va=0x20020000;
    range2.va_range$ps_end_va=0x20030000;
    id1.secid$l_version=0;
    id2.secid$l_version=0;
    fd=open("/file",O_RDONLY);

    sys$create_region_32(0x8000,0,0,0,0,0,range1.va_range$ps_start_va);
    sys$create_region_32(0x10000,0,0,0,0,0,range2.va_range$ps_start_va);

    sys$crmpsc(&range1,0,0,SEC$M_GBL,&gsdnam1,&id1,0,fd,2,0,0,0);
    sys$crmpsc(&range2,0,0,SEC$M_GBL,&gsdnam2,&id2,0,fd,2,1,0,0);

    for(i=0; i<4; i++)
    {
        volatile unsigned long * l1=range1.va_range$ps_start_va+0x2000;
        volatile unsigned long * l2=range2.va_range$ps_start_va+0x1000;
        (*l1)++;
        printf("%x %x\n",getpid(),*l1);
        sleep(2);
        (*l2)++;
        printf("%x %x\n",getpid(),*l2);
        sleep(2);
    }
    close(fd);
}
Example #17
0
void EGPlanner::threadLoop()
{
    bool done = false;
    while (!done) {
        PlannerState s = getState();
        switch (s) {
        case STARTING_THREAD: //do nothing
            break;
        case INIT:
            sleep(0.1);
            break;
        case READY:
            sleep(0.1);
            break;
        case RUNNING:
            mainLoop();
            break;
        case DONE:
            done = true;
            break;
        case EXITED: //Do nothing
            break;
        }
        if (!done) {
            checkTerminationConditions();
        }
    }
    setState(EXITED);
    DBGP("Thread is done!");
}
Example #18
0
File: unix.c Project: fkoner/core
void ProcessSignalTerminate(pid_t pid)
{
    if(!IsProcessRunning(pid))
    {
        return;
    }


    if(kill(pid, SIGINT) == -1)
    {
        CfOut(OUTPUT_LEVEL_ERROR, "kill", "!! Could not send SIGINT to pid %" PRIdMAX , (intmax_t)pid);
    }

    sleep(1);


    if(kill(pid, SIGTERM) == -1)
    {
        CfOut(OUTPUT_LEVEL_ERROR, "kill", "!! Could not send SIGTERM to pid %" PRIdMAX , (intmax_t)pid);
    }

    sleep(5);


    if(kill(pid, SIGKILL) == -1)
    {
        CfOut(OUTPUT_LEVEL_ERROR, "kill", "!! Could not send SIGKILL to pid %" PRIdMAX , (intmax_t)pid);
    }

    sleep(1);
}
Example #19
0
int
main(int argc, char *argv[])
{
    pid_t ppid;

    setbuf(stdout, NULL);       /* Disable buffering of stdout */

    switch (fork()) {
    case -1:
        errExit("fork");

    case 0:             /* Child */
        while ((ppid = getppid()) != 1) {   /* Loop until orphaned */
            printf("Child running (parent PID=%ld)\n", (long) ppid);
            sleep(1);
        }
        printf("Child is orphaned (parent PID=%ld)\n", (long) ppid);
        _exit(EXIT_SUCCESS);

    default:            /* Parent */
        printf("Parent (PID=%ld) sleeping\n", (long) getpid());
        sleep(3);                           /* Give child a chance to start */
        printf("Parent exiting\n");
        exit(EXIT_SUCCESS);
    }
}
int main() {
    pid_t pid;

    puts("pocz±tek programu");
    inicjalizacja_watkow();

    /* rejestrowanie funkcji wykonywanej w procesie potomnym */
    errno = pthread_atfork(NULL, NULL, inicjalizacja_watkow);
    test_errno("pthread_atfork");

    sleep(1);

    pid = fork();
    printf("fork => %d\n", pid);
    switch (pid) {
    case -1:
        test_errno("fork");
        break;

    case 0: // proces potomny
        sleep(2);
        break;

    default: // proces nadrzêdny
        waitpid(pid, NULL, 0);
        test_errno("waitpid");
        break;
    }

    /* koñczymy proces, bez ogl±dania siê na w±tki */
    return EXIT_SUCCESS;
}
Example #21
0
void*
Thread( void *pArg )
{
	int	Fd;

	sleep( 10 );

	Fd = (int)socket( AF_INET, SOCK_STREAM, 0 );
	if( Fd < 0 ) {
		perror("Thread:socket:");
		goto err;
	}

	printf("After 10sec connect\n");
	if( connect( Fd, (struct sockaddr*)&ADDR, sizeof(ADDR) ) < 0 ) {
		perror("Thread:connect:");
		goto err;
	}

	sleep( 1 );
	printf("pthread_exit\n");
	pthread_exit( 0 );
err:
	perror("SendThread");
	pthread_exit( 0 );
	return( NULL );
}
int main (int argc, char *argv[])
{
    void *handle = dlopen(argv[1], RTLD_LAZY);
    if (!handle)
    {
        fprintf(stderr, " Failed to load: %s because: %s\n", argv[1], dlerror());
        fflush(stderr);
        exit(RES_LOAD_FAILED);
    }

    while(!AfterAttach2())
    {
        sleep(1);
    }

    handle = dlopen(argv[2], RTLD_LAZY);
    if (!handle)
    {
        fprintf(stderr, " Failed to load: %s because: %s\n", argv[1], dlerror());
        fflush(stderr);
        exit(RES_LOAD_FAILED);
    }

    while(1)
    {
        // expected to be stopped by tool.
        sleep(1);
    }

    return RES_SUCCESS;
}
Example #23
0
int main(int argc, char* argv[]) {
    // Parse gflags. We recommend you to use gflags as well
    GFLAGS_NS::ParseCommandLineFlags(&argc, &argv, true);
    // set global log option

    if (FLAGS_dummy_port >= 0) {
        brpc::StartDummyServerAt(FLAGS_dummy_port);
    }

    pbrpcframework::PressOptions options;
    if (!set_press_options(&options)) {
        return -1;
    }
    pbrpcframework::RpcPress* rpc_press = new pbrpcframework::RpcPress;
    if (0 != rpc_press->init(&options)) {
        LOG(FATAL) << "Fail to init rpc_press";
        return -1;
    }

    rpc_press->start();
    if (FLAGS_duration <= 0) {
        while (!brpc::IsAskedToQuit()) {
            sleep(1);
        }
    } else {
        sleep(FLAGS_duration);
    }
    rpc_press->stop();
    // NOTE(gejun): Can't delete rpc_press on exit. It's probably
    // used by concurrently running done.
    return 0;
}
Example #24
0
int main()
{
	pthread_t new_th;

	if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0)
	{
		perror("Error creating thread\n");
		return PTS_UNRESOLVED;
	}

	sleep(1);

	if(pthread_kill(new_th, SIGTOTEST) != 0) 
	{
		printf("Test UNRESOLVED: Couldn't send signal to thread\n");
		return PTS_UNRESOLVED;
	}

	sem = INTHREAD;
	while (sem == INTHREAD)
		sleep(1);

	if(result == 2) {
		return PTS_UNRESOLVED;
	}
	if(result == 1) {
		return PTS_FAIL;
	}

	printf("Test PASSED\n");
	return PTS_PASS;	
}
Example #25
0
void simpleot_randombytes(unsigned char *x,unsigned long long xlen)
{
  int i;

  if (fd == -1) {
    for (;;) {
      fd = open("/dev/urandom",O_RDONLY);
      if (fd != -1) break;
      sleep(1);
    }
  }

  while (xlen > 0) {
    if (xlen < 1048576) i = xlen; else i = 1048576;

    i = read(fd,x,i);
    if (i < 1) {
      sleep(1);
      continue;
    }

    x += i;
    xlen -= i;
  }
}
Example #26
0
static void createDirectory(char* name) {
    int err;
    struct stat sb;

    err=stat(name, &sb);
    if(err==0) {
        if (!S_ISDIR(sb.st_mode)) {
            printf("%s exists but its not a directory\n",name);
            sleep(1);
            exit(1);
        }
    } else {
        if (errno==ENOENT) {
            err=mkdir(name, S_IRWXU);
            if (err!=0) {
                printf("mkdir failed; errno=%d\n",errno);
                exit(1);
            }
        }
        else if(errno==ENOTDIR) {
            printf("%s exists but its not a directory\n",name);
            sleep(1);
            exit(1);
        }
        else {
            perror("stat request error code");
            sleep(1);
            exit(1);
        }
    }
}
Example #27
0
void server()
{
while(1){
  P(p[99].full);
  printf("Server: Receiving \n");
  int a[10];
  receive(&p[99],a);
  int i=0;
 
  for(i=0;i<10;i++)
  printf("%d\t", a[i]);
  printf("\nServer: Receive Success \n");
  sleep(5);
  V(p[99].empty);
  //yield();
  P(p[a[0]].empty);
  printf("Server: Sending \n");
  for(i=0;i<10;i++) {
  a[i]+=10;
  printf("%d\t", a[i]);
  }
  printf("\n");
  
  send(&p[a[0]], a);
  for(i=0;i<10;i++)
  printf("%d\t", p[a[0]].msgs[p[a[0]].in-1][i]);
  printf("\n");
  printf("Server: Send success");
  sleep(5);
  V(p[a[0]].full);
  //yield();
}
}
int main()
{
    int shmid , status ;
    int *a , *b;
    int i;
    shmid = shmget(IPC_PRIVATE , 2*sizeof(int) , 0777|IPC_CREAT);
    if(fork()==0)
    {
        b = (int*)shmat(shmid , 0 , 0);
        for(i = 0;  i < 5 ; i++) {
            sleep(1);
            printf("Child reads %d %d\n",b[0],b[1]);
        }
        shmdt(b);
    }
    else
    {
        a = (int*)shmat(shmid , 0 , 0);
        a[0] = 0 , a[1] = 1;
        for(i = 0 ; i < 5 ; i++)
        {
            sleep(1);
            a[0] = a[0] + a[1];
            a[1] = a[0] + a[1];
            printf("Parent writes: %d,%d\n",a[0],a[1]);
        }
        wait(&status);
        shmdt(a);
        shmctl(shmid , IPC_RMID , 0);
    }
    return 0;
}
// Set the sensor to the selected frequency
void setHz(tSensors link, byte hertz) {
  byte msg[4] = { 3, 0x02, 0x41, 0x00 };

  if (hertz == 50) {
    msg[3] = 0x35;
  } else if (hertz == 60) {
    msg[3] = 0x36;
  } else {
    playSound(soundException);
    eraseDisplay();
    displayCenteredTextLine(3, "Wrong freq.");
    displayCenteredTextLine(3, "specified");
    sleep(5000);
    stopAllTasks();
  }

  while (nI2CStatus[link] == STAT_COMM_PENDING){
    sleep(5);
  }

  sendI2CMsg(link, &msg[0], 0);

  if (nI2CStatus[link] == ERR_COMM_BUS_ERR) {
    playSound(soundException);
    eraseDisplay();
    displayCenteredTextLine(3, "Error setting");
    displayCenteredTextLine(3, "sensor to 50Hz");
    sleep(5000);
    stopAllTasks();
  }
}
static void *philosopher(void *arg){
    int id = (int)arg;
    int i;
    printf("id %d begin!\n", id);
    for(i=0; i<10; i++){

        if((rand() % 100) > 90)
            sleep(1);
        printf("%d think\n", id);

        sem_wait(&num_allowed_to_eat);

        sem_wait(&forks[id]);
        sem_wait(&forks[(id + 1) % PH_COUNT]);

        if((rand() % 100) > 90)
            sleep(1);
        printf("%d eat\n", id);

        sem_post(&forks[id]);
        sem_post(&forks[(id + 1) % PH_COUNT]);

        sem_post(&num_allowed_to_eat);
    }
    printf("id %d done!\n", id);
    return NULL;
}