截图
代码
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <time.h>
#define INPUTLEN 100
//using namespace std;
int i;
void inthandler(int s){
int n = 0;
srand((unsigned int)time(NULL));
int A[10] = {-1};
int Temp = -1;
while (n<10)
{
Temp= rand()%100;
if(Temp%2 == 1)
{
A[n] = Temp;
}
else
{
A[n] = Temp +1;
}
n++;
}
for(int i=0;i<10;i++)
{
printf("%d ",A[i]);
}
printf("\n");
exit(0);
}
void quithandler(int s)
{
int n = 0;
srand((unsigned int)time(NULL));
int A[10] = {-1};
int Temp = -1;
while (n<10)
{
Temp= rand()%100;
if(Temp%2 == 0)
{
A[n] = Temp;
}
else
{
A[n] = Temp +1;
}
n++;
}
for(int i=0;i<10;i++)
{
printf("%d ",A[i]);
}
printf("\n");
exit(0);
}
int main(int argc, char *argv[])
{
void inthandler(int);
void quithandler(int);
char input[INPUTLEN];
int nchars;
signal(SIGINT, inthandler);//^C
signal(SIGQUIT, quithandler);//^\
do {
nchars = read(0, input, (INPUTLEN - 1));
if (nchars == -1)
perror("read returned an error");
}
while (strncmp(input, "quit", 4) != 0);
return 0;
}
标签:int,signal,间通信,测试,进程,include
From: https://www.cnblogs.com/daijun123/p/16875971.html