|
楼主 |
发表于 2006-4-23 12:19:33
|
显示全部楼层
[root@localhost soft]# gcc -o hello soft.c
soft.c: 在函数 ‘main’ 中:
soft.c:23: 警告:隐式声明与内建函数 ‘exit’ 不兼容
soft.c:30: 警告:隐式声明与内建函数 ‘exit’ 不兼容
soft.c:38: 警告:隐式声明与内建函数 ‘exit’ 不兼容
[root@localhost soft]# ./hello
Child process 1 is killed by parent !!
^[[3~^[[3~^[[3~Child process 2 is killed by parent !!
Parent process is killed !!
[root@localhost soft]#
按delete键出现^[[3~
其他的没有反应
,没打印stop()内容
[code:1]
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
int wait_flag;
void stop();
main() {
int pid1,pid2; //存储进程PID
signal(SIGINT,stop); //or signal(14,stop); 定义中断类型
while((pid1=fork())==-1); //创建进程
if(pid1>0) {
while((pid2=fork())==-1);
if(pid2>0) {
// wait_flag=1;
//sleep(4);
kill(pid1,16); //发送16
kill(pid2,17);
wait(0);
wait(0);
printf("Parent process is killed !!\n");
exit(0);
}
else {
// wait_flag=1;
sleep(5);
signal(17,stop);
printf("Child process 2 is killed by parent !!\n");
exit(0);
}
}
else {
// wait_flag=1;
//sleep(3);
signal(16,stop);
printf("Child process 1 is killed by parent !!\n");
exit(0);
}
}
void stop() {
printf("hehehee");
wait_flag=0;
}
[/code:1]
大哥指教
谢谢 |
|