#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>
#include <semaphore.h>
#include <wait.h>
#include <signal.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <semaphore.h>
#include <sys/msg.h>
#include <sys/shm.h>
#include <sys/un.h>
typedef struct sockaddr_in addr_in_t;
typedef struct sockaddr addr_t;
typedef struct sockaddr_un addr_un_t;
void handler(int signum)
{
if(signum==SIGCHLD)
{
printf("消灭b\n");
wait(0);
}
}
int main(int argc, const char* argv[]) {
int fd=open("1.txt",O_WRONLY|O_CREAT,0666);
int fd2=open("2.txt",O_WRONLY|O_CREAT,0666);
int arr[128]={0};
read(fd2,arr,sizeof(arr));
pid_t p=getpid();
write(fd2,&p,sizeof(p));
pid_t pid=fork();
if(pid>0)
{
signal(SIGCHLD,handler);
sleep(1);
}
else
{
kill(&arr,SIGCHLD);
}
printf("消灭B\n");
exit(0);
return 0;
}
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>
#include <semaphore.h>
#include <wait.h>
#include <signal.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <semaphore.h>
#include <sys/msg.h>
#include <sys/shm.h>
#include <sys/un.h>
typedef struct sockaddr_in addr_in_t;
typedef struct sockaddr addr_t;
typedef struct sockaddr_un addr_un_t;
void handler(int signum)
{
if(signum==SIGCHLD)
{
printf("消灭b\n");
wait(0);
}
}
int main(int argc, const char* argv[]) {
int fd=open("1.txt",O_WRONLY|O_CREAT,0666);
int fd2=open("2.txt",O_WRONLY|O_CREAT,0666);
int brr[128]={0};
read(fd1,arr,sizeof(arr));
pid_t p=getpid();
write(fd,&p,sizeof(p));
pid_t pid=fork();
if(pid>0)
{
kill(&brr,SIGCHLD);
signal(SIGCHLD,handler);
sleep(1);
}
else
{
exit(0);
}
printf("消灭B\n");
exit(0);
return 0;
}
2024.8.13
最新推荐文章于 2024-10-03 20:40:32 发布