2
I was trying to use top to monitor the performance of my codes in c, but when I run the program does not appear. Is it just not visible, or can’t monitor code in c using the top? What should I use to monitor if the top doesn’t work? The code is this:
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/stat.h>
int main(){
struct stat info;
pid_t id, filho;
struct timeval tv1, tv2;
double t1, t2;
id = getpid();
printf("Processo %ld \n", (long)id);
gettimeofday(&tv1, NULL);
lstat("teste", &info);
gettimeofday(&tv2, NULL);
t1 = (double)(tv1.tv_sec) + (double)(tv1.tv_usec)/ 1000000.00;
t2 = (double)(tv2.tv_sec) + (double)(tv2.tv_usec)/ 1000000.00;
printf("\nO tempo de execucao foi %lf\n", (t2 - t1));
_exit(0);
}
I use gcc -o dados dados.c
to compile the file. And ./dados
to run in the terminal. In the code itself it shows the pid of it and when I go to search in ps, I do not find.
The program runs very fast to appear in the top list. When you run _Exit(0) at the end the PID dies, it will no longer appear in ps or top...
– cemdorst
You have some tips on how to finish the program, so?
– Guilherme Almeida
I don’t know exactly what you want to monitor, but suddenly this lib can help you: man getrusage NAME getrusage -- get information about Resource Utilization SYNOPSIS #include <sys/Resource. h> #define RUSAGE_SELF 0 #define RUSAGE_CHILDREN -1
– cemdorst
I’m monitoring runtime, memory usage and processing. What you gave me just does not return processing, but it is still very helpful. If you know any q do this would be very good indeed. Thank you :)
– Guilherme Almeida
You’re welcome. Let me ask you. What do you define by "processing"? If the CPU percentage is used, just divide the user time by the real time.
– cemdorst
That’s right. These team'I can only use the command team?
– Guilherme Almeida
I waver my. What you’ve been through already does it. Thanks!
– Guilherme Almeida
I need to substantiate this test and I looked around here and I couldn’t find anything that says that the percentage of CPU is that calculation that you gave me. Where can I find this? Thanks in advance, now!
– Guilherme Almeida
I found this article very interesting (in English): http://www.linuxjournal.com/article/9001 .
– cemdorst