使用 daemon1 & daemons2 測試! daemon1 fork 出child process 而使用execv執行hello列印出簡單message.執行一段時間後daemon1被linux kernel kill!
trace:
src/linux/kernel/exit.c --> do_exit(long code) 加入debug message
printk(KERN_INFO "parent dead pid=%d status=%d\n",tsk->pid,code);
do_exit時code=4 --> SIGILL 非法指令
src/linux/arch/mips/icplus/setup.c --> ip218_detect_mem_size()
int main(int argc, char **argv)
{
pid_t pid,pid01;
pthread_t thread_id;
unsigned int loop_cnt=0;
char *args[] = { "/usr/bin/hello", NULL };
int fd[2];
int parent_fd;
int child_fd;
int status;
int pr;
int disp_cnt;
usleep(10000000);
pid01=getpid();
thread_id=pthread_self();
signal(SIGKILL,test_kill_01);
// signal(SIGCLD, test_kill_02);
signal(SIGHUP, test_kill_03);
signal(SIGSYS, test_kill_04);
signal(SIGTERM,test_kill_05);
signal(SIGSEGV,test_kill_06);
disp_cnt=0;
while(1)
{
if(disp_cnt==0)
printf("--------------------------------\n");
loop_cnt++;
if(disp_cnt==0)
printf("loop = %d\n",loop_cnt);
pid = fork();
if(pid < 0)
{
printf("fork fial ------------!!!\n");
exit(-1);
}
else if (pid==0){
if(disp_cnt==0)
printf("child S =%d %d\n",loop_cnt,getppid());
execve("/usr/bin/hello", args, NULL);
//execl("/bin/sh", "sh", "-c","cat /proc/uptime", (char *)0);
// execl("/bin/sh", "sh", "-c","/usr/bin/hello", (char *)0);
//execve("cat /proc/uptime", args, NULL);
printf("child E =%d\n",loop_cnt);
loop_cnt++;
exit(0);
}
else{
pr=waitpid(pid, &status, 0 );
//usleep(500000);
//loop_cnt++;
if(disp_cnt==0)
printf("parent =%d %d %d %d\n",loop_cnt,pid,getpid(),status);
}
if(disp_cnt==0)
printf("--------------------------------\n\n");
// disp_cnt++;
if(disp_cnt>10)
disp_cnt=0;
}
#if 0
out_main:
#endif
return 0;
}
test daemon2
int main(int argc, char **argv)
{
pid_t pid;
int sleep_cnt=0;
int disp_cnt=0;
int delay_cnt=0;
int delay_cnt1=0;
pid =getpid();
usleep(1000000);
printf("\n daemon2 %d, argc=[%d], sleep_cnt=[%d]", pid,argc, sleep_cnt);
fflush(stdout);
while(1)
{
sleep_cnt++;
if(sleep_cnt>900000){
sleep_cnt=0;
disp_cnt++;
if(disp_cnt>900000){
disp_cnt=0;
delay_cnt++;
if(delay_cnt>900000){
delay_cnt=0;
delay_cnt1++;
if(delay_cnt1>4){
delay_cnt1=0;
printf("\ndaemon2 %d is alive K----------------------->>\n",pid);
}
}
}
}
}
//out_main:
return 0;
}
留言列表