Thread: what does getitimer?

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    230

    what does getitimer?

    Hi! I am working on an exercise where i must count the time of a process. The problem is when using the getitimer. I searched google, read some staff and more over i understood what id does. My question is when exactly i should use it? To do what? I already used setitimer and signal. And i must count the times that every timer is zero. This number is how long the process worked. Can anyone help me? Thanks...

    For example in this code why should i use getitimer?

    Code:
    if(pid2 == 0){	/* 2o child */
    			
    			child2_PID = getpid();
    
    			/* enable the child 2 signal handlers (disable parent handlers) */
    			signal(SIGALRM, sig_handler); 			// συναγερμός 
    			signal(SIGVTALRM, sig_handler); 		// λήξη εικονικού χρονιστή
    			signal(SIGPROF, sig_handler); 			// λήξη χρονιστή προφίλ	
    
    			/* set the child 2 itimers */
    			setitimer(ITIMER_REAL, &c2_realt, NULL); 	// πραγματικός χρόνος πατέρα
    			setitimer(ITIMER_VIRTUAL, &c2_virtt, NULL); 	// χρόνος που εκτελέστηκε η διεργασία
    			setitimer(ITIMER_PROF, &c2_proft, NULL); 	// χρόνος που χρησιμοποιήσε η ο πυρήνας την CPU
    
    			/* start yourfunction() at child1 */
    			res = (funarg);
    
    			/* Read the child 1 itimer values and report them */
    			getitimer(ITIMER_PROF, &c2_realt);
    			getitimer(ITIMER_REAL, &c2_virtt);
    			getitimer(ITIMER_VIRTUAL, &c2_proft);
    
    			printf("Child2, Real time: %ld sec\n", c2_realt_secs);
    			printf("Child2, CPU time: %ld sec\n", c2_proft_secs);
    			printf("Child2, User time: %ld sec\n",  c2_virtt_secs);
    			//printf("Kernel -> %ld sec\n", p_proft_secs-c1_virtt_secs);
    			
    			printf("\n");
    			fflush(stdout);
    			exit(0);
    		}else{
    Last edited by brack; 03-08-2011 at 10:00 AM.

Popular pages Recent additions subscribe to a feed