- 1、本文档共137页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Ch4 Linux System Programming – Process IPC Jianjian SONG Software Institute, Nanjing University Oct, 2004 Content Process process environment Process Control Process identifier, fork, exec… Process relationship Signal Inter-process communication (IPC) Pipe, FIFO semaphore, shared memory, message queue Daemon Thread 1. Process Process Environment What is a process? Program and process Process: an address space with one or more threads executing within that address space, and the required system resources for those threads. (SUSv3) The startup of a process System call “fork” Process resources struct task_struct System space stack … System call “exec” The entry of C programs System stack The entry of C programs crt0.o cc/ld main function function prototype: int main(int argc, char *argv[]); The termination of a process Five ways of terminating a process Normal termination Return from “main” function Call “exit” function Call “_exit” function Abnormal termination Call “abort” function Terminated by a signal exit _exit functions Function prototype: #include stdlib.h void exit(int status); #include unistd.h void _exit(int status); Exit status Difference _exit is corresponding to a system call, while “exit” is a library function. _exit terminate a process immediately. Exit handler atexit function Register a function to be called at normal program termination. Prototype: #include stdlib.h int atexit(void (*function)(void)); on_exit function Example The memory map of a C program Text segment (code segment) Data segment Initialized data Uninitialized data Heap Stack Command line arguments main function int main(int argc, char *argv[]); Example: The implementation of echo(1) Command line option Standard usage getopt function getopt function Prototype: int getopt(int argc, char *const argv[], const char *optstring); extern char *optarg; extern int optind, opterr, optopt; Question: getopt(argc, argv, “if:lr”); Program example (P104, in BLP) Environment variables E
文档评论(0)