现在的位置: 首页 > 综合 > 正文

Linux编程实践—-信号的使用

2014年09月05日 ⁄ 综合 ⁄ 共 407字 ⁄ 字号 评论关闭
#include<iostream>
#include<sys/types.h>
#include<signal.h>
#include<unistd.h>
#include<stdlib.h>
using namespace std;
int main()
{
        cout<<"Father process is running!"<<endl;
        pid_t pid;
        pid=fork();
        if(-1==pid)
        {
                cout<<"Fork failed!"<<endl;
                exit(1);
        }
        if(0==pid) //Child process
        {
                cout<<"This is child process!"<<endl;
                kill(getppid(),SIGKILL);
                sleep(5);
                exit(0);
        }
        sleep(10);
        cout<<"This is father process!"<<endl;
        sleep(5);
        exit(0);

}

1.g++进行编译,运行结果为:


 

抱歉!评论已关闭.