- 10
- 0
- 约3.35万字
- 约 204页
- 2018-04-23 发布于河南
- 举报
计算机系统平台第4章
第4章 操作系统的内部实现机制 主要内容 进程的管理 内存的管理 信息存储的管理 外设的管理 struct task_struct struct task_struct {struct files_struct* files; //文件描述符struct signal_struct* sig; //信号控制signal handlerstruct mm_struct* mm;? ?? ???//内存管理模块long state;? ?? ?? ?? ?? ?? ?? ?? ?? ?//进程状态struct list_head runlist;? ?? ?? ?? ?? ?? ?? ?//用于链接RUN队列long priority;? ?? ?? ?? ???//基本优先权long counter;? ?? ?? ?? ?? ?//动态优先权char comm[];? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? //命令名struct thread_struct tss;? ? //上下文保存领域...}; state有下面几种状态: 状态? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?说明TASK_RUNNING? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? 执行可能状态TASK_INTERRUPTIBLE? ?? ?? ?? ?? ?? ?? ?? ?等待状态。可接受信号TASK_UNINTERRUPTIBLE? ?? ?? ?? ?? ?? ???等待状态。不能接受信号TASK_ZOMBIE? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? 僵尸状态。exit后的状态TASK_STOPPED? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???暂停状态 getpid getpid的作用很简单,就是返回当前进程的进程ID; 格式: #includesys/types.h /* 提供类型pid_t的定义 */ #includeunistd.h /* 提供函数的定义 */ pid_t getpid(void); 例:输出当前进程的PID /* getpid_test.c */ #includesys/types.h #includeunistd.h main() { printf(The current process ID is %d\n,getpid()); } $gcc getpid_test.c -o getpid_test $./getpid_test The current process ID is 1980 在2.4.4版内核中,fork是第2号系统调用,其在Linux函数库中的原型是: #include sys/types.h /* 提供类型pid_t的定义 */ #include unistd.h /* 提供函数的定义 */ pid_t fork(void); 例:fork系统调用创建进程,创建后父进程得到子进程的标识符,子进程得到值0。 #include stdio.h #include sys/types.h #include unistd.h int main() {int pid;printf(“Now this is process 1.\n”);printf(“System calling fork() will start.\n”);pid=fork();if (pid==0) printf(“This is child process.\n”);else if (pid0) printf(“This is process 1(parent process).\n”); else printf(“fork failed.\n”); exit(0); } 说明 pid=0时的分支是子进程运行部分;pid0时的部分是原进程(即父进程)运行部分。 通常情况是:if(pid==0) call subprocess_program;/*调用子进程处理程序*/else if (pid0) complete parent_process_program;/*完成父进程处理程序*/ 注意:父进程和子进程是并发执行。由于父、子进程具有相同的优先级,所以父、子进程运行的顺序是随机的。 例. fork 应用 int i=1;
您可能关注的文档
- 2技术文件和图纸.doc
- 初中英语ppt.ppt
- VOA官方英语词汇.doc
- 关于比较和比较级的用法.ppt
- 国家基本药物贵州省增补药品目录(2012版).doc
- 哈尔餐饮业问卷.doc
- 建筑给水排水工程课设计算书.doc
- 文件管理器设计报告.doc
- 044涂料防水层检验批质量验收记录.doc
- 改资料交接台帐.doc
- 2025-2026学年天津市和平区高三(上)期末数学试卷(含解析).pdf
- 2025-2026学年云南省楚雄州高三(上)期末数学试卷(含答案).pdf
- 2025-2026学年甘肃省天水市张家川实验中学高三(上)期末数学试卷(含答案).docx
- 2025-2026学年福建省厦门市松柏中学高二(上)期末数学试卷(含答案).docx
- 2025-2026学年广西钦州市高一(上)期末物理试卷(含答案).docx
- 2025-2026学年河北省邯郸市临漳县九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省石家庄二十三中七年级(上)期末历史试卷(含答案).docx
- 2025-2026学年海南省五指山市九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省唐山市玉田县九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省邢台市市区九年级(上)期末化学试卷(含答案).docx
最近下载
- 兰科植物促生菌筛选与人工栽培技术研究.pdf
- 氢氧化钠(片碱)MSDS安全技术说明书.docx
- 国家开放大学电大《成本会计》试题及答案.pdf
- 数学分析第四版下册课后习题答案.pdf
- 数学分析第四版下册课后习题答案.docx
- 2025年秋国家开放大学《商务英语3》形考任务参考答案.pdf
- Unit 2 Know your body Speed up 外研版(三起)(2024)英语三年级下册.pptx VIP
- 2026年春季开学教师收心会校长发言:骏驰启新程,笃行育新人;凝心再聚力,实干谱新篇.docx VIP
- Unit 2 Know your body Start up 外研版(三起)(2024)英语三年级下册.pptx VIP
- 空客A320飞行手册教程.doc VIP
原创力文档

文档评论(0)