--------------------------
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
void handler(int signo)
{
printf("recv the signal from parent process\n")
}
int main()
{
pid_t pid
pid = fork()
switch(pid)
{
case -1:
perror("fork failed")
exit(1)
case 0:
printf("in the child\n")
signal(SIGCONT, handler)
pause()
printf("child weakup\n")
break
default:
printf("in the parent\n")
sleep(5)
kill(pid, SIGCONT)
sleep(5)
printf("parent weakup\n")
break
}
printf("bye..\n")
exit(0)
}
--------------------------------------------------
运行及输出:
beyes@linux-beyes:~/C>./weakup.exe
in the child
in the parent
recv the signal from parent process
child weakup
bye..
parent weakup
bye..
....................................
/*以下是我写的一个简单的进程创建过程,VC6.0下编译通过,注释我就没写了,如果你看不懂的话百度追问我一下,如果帮上你了的话就选我吧*/#include "windows.h"
#include "stdio.h"
int main()
{
char a
PROCESS_INFORMATION processInfo
DWORD ExitCode
STARTUPINFO startInfo
GetStartupInfo(&startInfo)
CreateProcess(NULL,"notepad.exe a.txt",NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,
NULL,NULL,&startInfo,&processInfo)
printf("是否结束线程?Y/N\n")
if(getchar(a)=='Y')
{
GetExitCodeProcess(processInfo.hProcess,&ExitCode)
if(ExitCode==STILL_ACTIVE)
{
TerminateProcess(processInfo.hProcess,0)
CloseHandle(processInfo.hProcess)
processInfo.hProcess=0
}
else
printf("进程已被关闭\n")
}
else
{
printf("您选择不关闭进程,如需结束进程请自行手动关闭!\n")
}
return 0
}
struct pb{int n
int k
int cha}
typedef struct pb PCB
PCB a[10]void creat()
{static int pi=1
int k,l=0,m
printf("plase input n0:")
scanf("%d",&m)
for(k=1k<=10k++)
if (a[k].n==m)
l=1
if (l==1)
{printf("error!\n")
creat()}
else
{a[pi].n=m
printf("\n")
printf("plase input k0:")
scanf("%d",&a[pi].k)
printf("\n")
a[pi++].cha=4}}void destory()
{int i,num,k=0
printf(" plase input destory number:")
scanf("%d",&num)
for(i=1i<=10i++)
if(a[i].n==num) k=i
if(k!=0)
{a[k].n=0a[k].k=0a[k].cha=0}
else
printf("No have this destory number!\n")}void wakeup()
{int i,k,m,l
printf("请输入n0:")
scanf("%d",&m)
for(k=1k<=10k++)
if (a[k].n==m)
l=k
a[l].cha=1 /*唤醒->静止就绪*/}void active()
{int i,k,m,l
printf("请输入n0:")
scanf("%d",&m)
for(k=1k<=10k++)
if (a[k].n==m)
l=k
a[l].cha=3/*激活->活动就绪*/}void dse()
{int i,k,m,l
printf("请输入n0:")
scanf("%d",&m)
for(k=1k<=10k++)
if (a[k].n==m)
l=k
a[l].cha=4 /*阻塞->活动阻塞*/}void swpend()
{int i,k,m,l
printf("请输入n0:")
scanf("%d",&m)
for(k=1k<=10k++)
if (a[k].n==m)
l=k
a[l].cha=2/* 挂起->静止阻塞 */}void look()
{int i
printf("\t\t�pcb n0 k0 cha\n")
for (i=1i<=10i++)
printf("\t\t%d\t%d\t%d\t%d\n",i,a[i].n,a[i].k,a[i].cha)
printf("\t1--静止就绪 2--静止阻塞 3--活动就绪 4--活动阻塞 5--运行\n")}void zt() /* 改变状态*/
{int i,k,m,l
printf("请输入n0:")
scanf("%d",&m)
for(k=1k<=10k++)
if (a[k].n==m)
l=k
printf("请输入当前状态:")
scanf("%d",&a[l].cha)
look()}void yxs() /*改变优先数*/
{int i,k,m,l
printf("请输入n0:")
scanf("%d",&m)
for(k=1k<=10k++)
if (a[k].n==m)
l=k
printf("请输入优先数:")
scanf("%d",&a[l].k)
look()}main()
{int d
clrscr()
do
{
printf("\t\t*************** CHOICE *****************\n")
printf("\t\t* 1--------------进程创建 *\n")
printf("\t\t* 2--------------进程撤消 *\n")
printf("\t\t* 3--------------阻塞 *\n")
printf("\t\t* 4--------------唤醒 *\n")
printf("\t\t* 5--------------挂起 *\n")
printf("\t\t* 6--------------激活 *\n")
printf("\t\t* 7--------------查看状态 *\n")
printf("\t\t* 8--------------改变状态 *\n")
printf("\t\t* 9--------------改变优先数 *\n")
printf("\t\t* 0--------------退出 *\n")
printf("\t\t****************************************\n")
printf("\t\t�请选择(0-9):")
scanf("%d",&d)
printf("\n")
switch(d)
{
case 1: creat()break
case 2: destory()break
case 3: dse()break
case 4: wakeup()break
case 5: swpend()break
case 6: active()break
case 7:look()break
case 8:zt()break
case 9:yxs()break
case 0: exit(0)
}
}
while(d!=0)
}