kill SIGKILL
raise 向自己的进程发送函数
SIGALRM 不是立马发送 是定时等待发出 定时一段时间才发信号 只能发送给当前进程 和raise 一样
uint alarm(uint second)没有告诉内核发送什么信号 让内核延迟second 的时间再发送
发送给当前进程 在信号接受前进程不能结束 收到信号终止进程
信号的接收
sleep
pause 当前进程处于睡眠状态
ctrl +Z SIGTSTP
ctrl +c 键盘驱动来发送 SIGINT 信号在用用户输入 字符Ctrl+c时候发出 终止终端驱动程序发送此信号 并送到前台进程中的每一个进程
信号的处理
signal 自己处理信号的方法告诉 这样收到信号的进程就会按你的方式处理
void (*signal(int signum,void (*handler(int )))(int));
void (*handler)(int) 函数指着变量
返回值 函数指针
signal 处理 那个信号 告诉内核怎么处理这个信号
SIG_IGN 忽略该信号
SIG_DFL 采用系统默认方式处理信号
自定义的信号处理函数指针
告诉内核 处理哪一个信号 第二个 按什么方式处理
signal(14,SIG_IGN) 忽略信号
IPC
共享内存
信号灯
消息队列
进程A 和进程B 通信 通过内核的IPC 内核空间是不存在的 必须在内核空间里创建 最后删除 和文件IO处理思想是一样的 函数形式不一样 
{int shmid;
shmid=shmget(IPC_PRIVATE,128,0777);//每次用IPC_PRIVATE 操作时共享内存的key都是一样的都是0 有缘
//ftok 获得 无缘
IF(shmid<0)
{
printf("create shar memory failure\n");
return -1;
}
printf("create share memory success shmid%d\n",shmid);
system("ipcs -m");
}
将内存映射到用户空间的地址中去
不必每次进入到内核读写
shmat(int shmid ,const void *shmaddr ,int shmflg);
共享内存创建之后 一直存在内核中 直到被删除或者被系统关闭
共享内存和管道不一样 读取之后 内存仍然窜在其共享内存中
使用完需要释放共享内存
shmget 创建缓存
shmat
shmdt
shmctl
ftok 用来创建key 给shmget第一个参数用
无缘进程之间的共享内存 通信
服务器
#include "sys/types.h"
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/shm.h>
struct mybuf{
int pid;
char buf[128];
};
void myfun()
{
return ;
}
int main()
{
int shmid;
int key;
struct mybuf *p;
int pid;
key=ftok("./a.c",'a');
if(key<0)
{
printf("ftok failure\n");
return -2;
}
printf("create key success\n");
shmid=shmget(key,128,IPC_CREAT |0777);
if(shmid<0)
{
printf("create share momery failure\n");
return -1;
}
printf("create share momery success shmid =%d\n",shmid);
signal(SIGUSR2,myfun);
p=(struct mybuf *)shmat(shmid,NULL,0);
if(p==NULL)
{
printf("parent process shmat failure\n");
return -3;
}
p->pid=getpid();
pause();// client read server pid
pid=p->pid;
while(1)
{
printf("parent process start write share memory:\n");
fgets(p->buf,128,stdin);
kill(pid ,SIGUSR1);
pause();//wait client proces read
}
return 0;
}
客户端
#include "sys/types.h"
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/shm.h>
struct mybuf{
int pid;
char buf[128];
};
void myfun()
{
return ;
}
int main()
{
int shmid;
int key;
struct mybuf *p;
int pid;
key=ftok("./a.c",'a');
if(key<0)
{
printf("ftok failure\n");
return -2;
}
printf("create key success\n");
shmid=shmget(key,128, IPC_CREAT| 0777);
if(shmid<0)
{
printf("create share momery failure\n");
return -1;
}
printf("create share momery success shmid =%d\n",shmid);
signal(SIGUSR1,myfun);
p=(struct mybuf *)shmat(shmid,NULL,0);
if(p==NULL)
{
printf("parent process shmat failure\n");
return -3;
}
//read share memory
pid=p->pid;
p->pid=getpid();
kill(pid,SIGUSR2);//kill signal
while(1)
{
pause();//Wait server write data to share memory
printf("client process receve data from memory :%s\n",p->buf);
kill(pid,SIGUSR2); // SERVER CAN WRITE SHARE MEMORY
}
return 0;
}