void linux_survey_TT(int, char *)
to your Linux kernel so that you can
call it in your program. The system call has the following properties.
void linux_survey_TT()
.
bash
on your Linux host with a 32-bit architecture.
You can use command ps
to obtain the PID of this process.
bash
is called process 1
hereafter.
bash
, execute another
bash
.
bash
programs.
test.c
as follows to collect the information you need.
Execute this program after your start all required programs.
#include <stdio.h>
#include <unistd.h>
#define MEMORY_SIZE 1000000
main()
{ int i,pid;
int result_1[MEMORY_SIZE];
int result_2[MEMORY_SIZE];
: // Definition of other varialbes you need to use in your program
: // Your initialization code
printf("Input the PID of the first firefox
that you want to observe:");
scanf("%d", &pid);
linux_survey_TT(pid,result_1);
printf("Input the PID of the second firefox
that you want to observe:");
scanf("%d", &pid);
linux_survey_TT(pid,result_2);
: // Code to process results contained in rslt_1[MEMORY_SIZE] and rslt_2[MEMORY_SIZE]
: // Code to report the final results
}
void linux_survey_TT()
, list the corresponding physical address intervals used by the above virtual address intervals at the moment that you execute system call
void linux_survey_TT()
.
$ cat /proc/<pid>/maps
P.S.: <pid> is the process id of your process.
void linux_survey_VV(char *)
to your Linux kernel so that you can
call it in your program. The system call has the following properties.
void linux_survey_VV()
.
program.c
written by
Tim as follows
to collect the information you need.
Execute this program after your start all required programs.
#include <stdio.h>
#include <pthread.h>
#define MEMORY_SIZE 1000000
int result_1[MEMORY_SIZE];
int result_2[MEMORY_SIZE];
/* this function is run by the second thread */
void *inc_x(void *x_void_ptr)
{
/* increment x to 100 */
int *x_ptr = (int *)x_void_ptr;
while(++(*x_ptr) < 100);
printf("x increment finished\n");
linux_survey_VV(result_1);
/* the function must return something - NULL will do */
return NULL;
}
int main()
{
int x = 0, y = 0;
/* show the initial values of x and y */
printf("x: %d, y: %d\n", x, y);
/* this variable is our reference to the second thread */
pthread_t inc_x_thread;
/* create a second thread which executes inc_x(&x) */
if(pthread_create(&inc_x_thread, NULL, inc_x, &x)) {
fprintf(stderr, "Error creating thread\n");
return 1;
}
/* increment y to 100 in the first thread */
while(++y < 100);
printf("y increment finished\n");
linux_survey_VV(result_2);
/* wait for the second thread to finish */
if(pthread_join(inc_x_thread, NULL)) {
fprintf(stderr, "Error joining thread\n");
return 2;
}
/* show the results - x is now 100 thanks to the second thread */
printf("x: %d, y: %d\n", x, y);
: // Code to process and report the final results
return 0;
}
pthread
library,
e.g. gcc -lpthread program.c
.