应用程序结构null应用程序结构(计算模型)应用程序结构(计算模型)单进程
多进程
多线程
有限状态机
数据流
例子
一系统等待用户输入两个正整数X和Y,然后系统每隔X秒种输出“Hello World”,每隔Y秒种输出“How are you”单进程单进程I = 1;
T = 0;
Read X, Y
while (1) {
Delay(I); T = T + I
if T mod X is 0 then call PrintHelloWorld
if T mod Y is 0 then call PrintHowAreYou...
null应用程序结构(计算模型)应用程序结构(计算模型)单进程
多进程
多线程
有限状态机
数据流
例子
一系统等待用户输入两个正整数X和Y,然后系统每隔X秒种输出“Hello World”,每隔Y秒种输出“How are you”单进程单进程I = 1;
T = 0;
Read X, Y
while (1) {
Delay(I); T = T + I
if T mod X is 0 then call PrintHelloWorld
if T mod Y is 0 then call PrintHowAreYou
}多进程多进程多进程多进程有限状态机(FSM)有限状态机(FSM)null#define IDLE 0
#define GOINGUP 1
#define GOINGDN 2
#define DOOROPEN 3
void UnitControl()
{
int state = IDLE;
while (1) {
switch (state) {
IDLE: up=0; down=0; open=1; timer_start=0;
if (req==floor) {state = IDLE;}
if (req > floor) {state = GOINGUP;}
if (req < floor) {state = GOINGDN;}
break;
GOINGUP: up=1; down=0; open=0; timer_start=0;
if (req > floor) {state = GOINGUP;}
if (!(req>floor)) {state = DOOROPEN;}
break;
GOINGDN: up=1; down=0; open=0; timer_start=0;
if (req > floor) {state = GOINGDN;}
if (!(req>floor)) {state = DOOROPEN;}
break;
DOOROPEN: up=0; down=0; open=1; timer_start=1;
if (timer < 10) {state = DOOROPEN;}
if (!(timer<10)){state = IDLE;}
break;
}
}
}数据流式(DataFlow)数据流式(DataFlow)三要素:接口、进程、数据存储nullIPCIPC信号(signal)
管道(pipe)
消息队列(message queue)
信号量(semaphore)
共享存储(shared memory)nullSemaphores:producer-consumernullShared variable total = 0;
P1:
Int count;
For (count = 0; count <=50; count ++)
total ++;
P2:
Int count;
For (count = 0; count <=50; count ++)
total ++;
共享存储共享存储linux的共享存储沿用了SYSV IPC机制。进程利用共享存储进行通讯时,先向内核申请一个共享存储段。成功后把它添加(attach)到自己的地址空间,然后象使用普通存储器一样使用它。
共享存储限制:
一个共享存储段的大小限制:SHMMAX:4M, SHMMIN:1byte(实际是一个page大),系统中允许的共享存储段的个数限制:SHMMNI:4096。系统中允许的共享存储段占总页面数:SHMALL:2M个页面
这些参数可以由超级用户修改,如:
#echo 2048 >/proc/sys/kernel/shmmni
共享存储管理系统调用:shmget,shmat,shmdt,shmctl nullshm_server.c
#include
#include
#include
#include
#define SHMSZ 27
main(){
char c; int shmid; key_t key; char *shm, *s;
key = 5678;
if ((shmid = shmget(key,SHMSZ,IPC_CREAT|0666))< 0)
{ perror("shmget"); exit(1); }
if ((shm = shmat(shmid,NULL,0))==(char *)-1)
{ perror("shmat"); exit(1); }
s = shm;
for (c = 'a'; c <= 'z'; c++)
*s++ = c;
*s = NULL;
while (*shm != '*')
sleep(1);
exit(0);
} Example: IPC using shared memorynullshm_client.c
/* shm-client - client program to demonstrate shared memory. */
#include
#include
#include
#include
#define SHMSZ 27
main(){
int shmid;
key_t key;
char *shm, *s;
key = 5678;
if ((shmid = shmget(key, SHMSZ, 0666)) < 0)
{ perror("shmget"); exit(1); }
if ((shm = shmat(shmid, NULL, 0)) == (char *) -1)
{ perror("shmat"); exit(1); }
for (s = shm; *s != NULL; s++)
putchar(*s);
putchar('\n');
*shm = '*';
exit(0);
} Linux内核分析Linux内核分析2.6内核关于进程调度的分析
进程队列的管理及选择进程的方法
调度时机:内核抢占
NPTL(Native Pthread Library)分析
2.6内核关于存储管理的改进
MemoryPool的作用与实现机制
本文档为【应用程序结构】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。