进程模型测试程序
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <pthread.h>
//extern int errnop;
//extern int errno;
extern _text;
extern _etext;
extern _data;
extern _edata;
//extern char *environ[];
int i_initialized = 1; /* initialized global variable. */
long l_uninitialized; /* uninitialized global variable. */
//int g_i300;
void thread_sub_func(void* param)
{
int i_val2;
printf("param = \t\t0x%016p\n",¶m);
printf("i_val2 = \t\t0x%016p\n",&i_val2);
printf("size = \t\t%lld\n",(long long)param-(long long)&i_val2);
//memset(&i_val2,0,124);
}
void thread_func()
{
int i_val;
printf("i_val = \t\t0x%016p\n",&i_val);
int* pi = new int();
if(pi == NULL)
{
fprintf(stderr,"分配内存失败\n");
return;
}
printf("pi = \t\t0x%016p\n",pi);
char* pMalloc;
if((pMalloc = (char*) malloc(10)) == NULL)
{
return;
}
printf("pMalloc = \t\t0x%016p\n",pMalloc);
thread_sub_func(&i_val);
while(true)
{
fprintf(stdout,"pthread...\n");
sleep(1);
}
}
int
main(int argc, char *argv[])
{
typedef void *(*FUNC)(void *);
char str_buf[BUFSIZ]; /* auto storage class variable. */
char *heap_mem; /* heap memory. */
if ((heap_mem = (char*)malloc(BUFSIZ)) == /*(void *)*/NULL) {
sprintf(str_buf, "malloc() failed with errno = %d", errno);
perror(str_buf);
}
printf("_text =\t\t\t0x%016p\n", &_text);
printf("_etext =\t\t0x%016p\n", &_etext);
printf("_data =\t\t\t0x%016p\n", &_data);
printf("_edata =\t\t0x%016p\n", &_edata);
printf("argv[] =\t\t0x%016p\n", argv);
//printf("environ[] =\t\t0x%016p\n", environ);
//printf("errnop =\t\t0x%016p\n", &errnop);
//printf("errno =\t\t\t0x%016p\n", &errno);
printf("i_initialized = \t0x%016p\n", &i_initialized);
//printf("g_i300 = \t0x%016p\n",&g_i300);
printf("l_uninitialized = \t0x%016p\n", &l_uninitialized);
printf("str_buf = \t\t0x%016p\n", str_buf);
printf("heap_mem = \t\t0x%016p\n", heap_mem);
pthread_t tid;
if(pthread_create(&tid,NULL,FUNC(thread_func),NULL))
{
fprintf(stderr,"创建线程失败\n");
exit(0);
}
pthread_join(tid,NULL);
exit(0);
}
#include <stdio.h>
#include <errno.h>
#include <pthread.h>
//extern int errnop;
//extern int errno;
extern _text;
extern _etext;
extern _data;
extern _edata;
//extern char *environ[];
int i_initialized = 1; /* initialized global variable. */
long l_uninitialized; /* uninitialized global variable. */
//int g_i300;
void thread_sub_func(void* param)
{
int i_val2;
printf("param = \t\t0x%016p\n",¶m);
printf("i_val2 = \t\t0x%016p\n",&i_val2);
printf("size = \t\t%lld\n",(long long)param-(long long)&i_val2);
//memset(&i_val2,0,124);
}
void thread_func()
{
int i_val;
printf("i_val = \t\t0x%016p\n",&i_val);
int* pi = new int();
if(pi == NULL)
{
fprintf(stderr,"分配内存失败\n");
return;
}
printf("pi = \t\t0x%016p\n",pi);
char* pMalloc;
if((pMalloc = (char*) malloc(10)) == NULL)
{
return;
}
printf("pMalloc = \t\t0x%016p\n",pMalloc);
thread_sub_func(&i_val);
while(true)
{
fprintf(stdout,"pthread...\n");
sleep(1);
}
}
int
main(int argc, char *argv[])
{
typedef void *(*FUNC)(void *);
char str_buf[BUFSIZ]; /* auto storage class variable. */
char *heap_mem; /* heap memory. */
if ((heap_mem = (char*)malloc(BUFSIZ)) == /*(void *)*/NULL) {
sprintf(str_buf, "malloc() failed with errno = %d", errno);
perror(str_buf);
}
printf("_text =\t\t\t0x%016p\n", &_text);
printf("_etext =\t\t0x%016p\n", &_etext);
printf("_data =\t\t\t0x%016p\n", &_data);
printf("_edata =\t\t0x%016p\n", &_edata);
printf("argv[] =\t\t0x%016p\n", argv);
//printf("environ[] =\t\t0x%016p\n", environ);
//printf("errnop =\t\t0x%016p\n", &errnop);
//printf("errno =\t\t\t0x%016p\n", &errno);
printf("i_initialized = \t0x%016p\n", &i_initialized);
//printf("g_i300 = \t0x%016p\n",&g_i300);
printf("l_uninitialized = \t0x%016p\n", &l_uninitialized);
printf("str_buf = \t\t0x%016p\n", str_buf);
printf("heap_mem = \t\t0x%016p\n", heap_mem);
pthread_t tid;
if(pthread_create(&tid,NULL,FUNC(thread_func),NULL))
{
fprintf(stderr,"创建线程失败\n");
exit(0);
}
pthread_join(tid,NULL);
exit(0);
}