当前位置: 首页 > news >正文

保定免费网站建站模板手机软件怎么做出来的

保定免费网站建站模板,手机软件怎么做出来的,部署wordpress,凡科网站建设视频若子进程先于父进程结束时#xff0c;父进程调用wait()函数和不调用wait()函数会产生两种不同的结果#xff1a; -- 如果父进程没有调用wait()和waitpid()函数#xff0c;子进程就会进入僵死状态。 -- 如果父进程调用了wait()和waitpid()函数#xff0c;就不会使子… 若子进程先于父进程结束时父进程调用wait()函数和不调用wait()函数会产生两种不同的结果 -- 如果父进程没有调用wait()和waitpid()函数子进程就会进入僵死状态。 -- 如果父进程调用了wait()和waitpid()函数就不会使子进程变为僵尸进程。 这是为什么呢现在我们来深入学习wait()函数和waitpid()函数。   wait() 和 waitpid() 学习 1、首先我们先看一下它们的函数原型 在终端输入命令man 2 wait 就会看到它的函数原型 NAME        wait, waitpid, waitid - wait for process to change state SYNOPSIS        #include sys/types.h        #include sys/wait.h        pid_t wait(int *status);        pid_t waitpid(pid_t pid, int *status, int options);        int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options); 我们可以看到在2.6版本中新增叫了 waitid() 函数。   2、wait() 和 waitpid() 的功能 1 wait()函数使父进程暂停执行直到它的一个子进程结束为止该函数的返回值是终止运行的子进程的PID参数status所指向的变量存放子进程的退出码即从子进程的main函数返回的值或子进程中exit()函数的参数。如果status不是一个空指针状态信息将被写入它指向的变量。 注意进程一旦调用了wait就立即阻塞自己由wait自动分析是否当前进程的某个子进程已经退出如果让它找到了这样一个已经变成僵尸的子进程wait 就会收集这个子进程的信息 并把它彻底销毁后返回如果没有找到这样一个子进程wait就会一直阻塞在这里直到有一个出现为止。 2 头文件sys/wait.h中定义了进程退出状态的宏。 我们首先看下官方的解释 a.WIFEXITED(status)     returns true if the child terminated normally, that is, by calling exit(3) or _exit(2), or by returning from main() . 翻译 WIFEXITED(status)  若子进程是正常结束时则返回一个非零值。即调用exit(3)_exit(3) 或从main()函数返回的值。   b. WEXITSTATUS(status)   returns the exit status of the  child.   This  consists  of  the least  significant  8 bits of the status argument that the child specified in a call to exit(3) or _exit(2) or  as  the  argument for  a return  statement  in main().  This macro should only be employed if WIFEXITED returned true. 翻译 WEXITSTATUS(status)    如果宏WIFEXIED返回值为非零值时它返回子进程中exit或_exit参数中的低8位。   c.WIFSIGNALED(status)  returns true if the child process was terminated by a signal. 翻译 WIFSIGNALED(status)  若子进程异常终止则返回一个非零值。   d. WTERMSIG(status)   returns the number of the signal that caused the  child  process  to terminate.  This macro should only be employed if WIFSIGNALED returned true. 翻译 WTERMSIG(status)      如果宏WIFSIGNALED的返回值非零则返回使子进程异常终止的信号编号。   e.WIFSTOPPED(status)   returns true if the child process was stopped by delivery  of a signal;  this  is  only possible if the call was done using WUN‐TRACED or when the child is being traced (see ptrace(2)). 翻译 WIFSTOPPED(status)  若子进程由于异常暂停则返回一个非零值。当调用WUN‐TRACED或子进程被跟踪时这才时可能的。   f. WSTOPSIG(status)    returns the number of the signal which caused the child to stop.This macro should only be employed if WIFSTOPPED returned true. 翻译 WSTOPSIG(status)      如果宏WIFSTOPPED返回值非零则返回使子进程暂停的信号编号。   g.WIFCONTINUED(status)     (since  Linux  2.6.10)  returns  true  if  the child process wasresumed by delivery of SIGCONT. 翻译 WIFCONTINUED(status)     (从2.6版本后如果孩子进程通过SIGCONT恢复则返回一个非零值。   3waitpid() 函数 (1).我们先来看一个waitpid()的经典例子当我们下载了A软件的安装程序后在安装快结束时它又启动了另外一个流氓软件安装程序B当B也安装结束后才告诉你所有安装都完成了。A和B分别在不同的进程中A如何启动B并知道B安装完成了呢可以很简单地在A中用fork启动B然后用waitpid()来等待B的结束。 (2).waitpid()也用来等待子进程的结束但它用于等待某个特定进程结束。参数pid指明要等待的子进程的PID参数status的含义与wait()函数中的status相同。options参数可以用来改变waitpid的行为若将该参数赋值为WNOHANG则使父进程不被挂起而立即返回执行其后的代码。 (3).waitpid()函数中参数pid的取值 还是先看下官方解释  The value of pid can be:        -1   meaning  wait  for  any  child process whose process group ID is equal to the absolute value of pid.        -1     meaning wait for any child process.        0      meaning wait for any child process whose  process  group  ID  is equal to that of the calling process.        0    meaning  wait  for  the  child  whose process ID is equal to the value  of pid. 翻译 pid的值可以为下己中情况    -1  等待其组D等于pid绝对值的任一子进程。   -1  等待任一子进程    等待其组等于调用进程的组ID的任一进程    0  等待其进程ID等于pid的子进程退出 (4).waitpid()函数的一个应用 如果想让父进程周期性地检查某个特定的子进程是否已经退出可以用下面的方法 waitpid(child_pid, (int *) 0, WNOHANG); 如果子进程尚未退出它将返回如果子进程已经结束则返回child_pid。调用失败时返回。失败的原因包括没有该子进程参数不合法等。   3、wait()和waitpid() 函数的区别 (1).在一个子进程终止前wait()使其调用者阻塞而waitpid()有一个选项可使调用者不阻塞。 (2).waitpid()并不等待在其调用之后的第一个终止子进程它有若干个选项可以控制它所等待的进程。 (3).对于wait()其唯一的出错是调用进程没有子进程对于waitpid()若指定的进程或进程组不存在或者参数pid指定的进程不是调用进程的子进程都可能出错。 (4).waitpid()提供了wait()没有的三个功能一是waitpid()可等待一个特定的进程二是waitpid()提供了一个wait()的非阻塞版本有时希望取的一个子进程的状态但不想使父进程阻塞waitpid() 提供了一个这样的选择WNOHANG它可以使调用者不阻塞三是waitpid()支持作业控制。 (5).wait(status) 的功能就等于 waitpid(-1, status, 0);   函数实例 有时希望取的一个子进程的状态但不想使父进程阻塞waitpid() 提供了一个这样的选择WNOHANG它可以使调用者不阻塞 #include sys/wait.h #include unistd.h #include stdio.hint main() {pid_t pr, pc;do{pr waitpid(pc, NULL, WNOHANG);if (pr 0){printf(No child exited\n);sleep(1);}}while (pr 0);if (pr pc){printf(successfully get child %d\n, pr);}else{printf(some error occured\n);}return 0; }   总结 无论进程是否正常终止内核都会向其父进程发送SIGCHLD 信号当调用wait或waitpid函数时 (a) 如果所有的子进程都在run 可以阻塞父进程。 (b) 如果子进程终止则wait立即返回子进程终止状态。 (c) 如果没有子进程在运行, 立即返回error。   4、函数实现 函数实例1.(先看一个简单的实例看看进程调用wait()函数后是如何执行的) #includestdio.h #includesys/types.h #includesys/wait.h #includeunistd.h #includestdlib.hint main() {pid_t child;int i;child fork();if (child 0){printf(create failed!\n);exit(1);}else if (0 child){printf(this is the child process pid %d\n, getpid());for (i 0; i 5; i){printf(this is the child process print %d !\n, i 1);}printf(the child end\n);}else{printf(this is the father process, ppid%d\n, getppid());printf(father wait the child end\n);wait(child);printf(father end\n);} } 函数经过编译 gcc wait.c -o wait ./wait 函数执行结果 this is the father process, ppid3303 father wait the child end this is the child process pid 3356 this is the child process print 1 ! this is the child process print 2 ! this is the child process print 3 ! this is the child process print 4 ! this is the child process print 5 ! the child end father end   说明 从上面的程序我们可以深入的了解wait() 函数的执行过程 当父进程调用wait()函数后被挂起等待直到子进程结束为止。   函数实例2现在我们在通过一个实例来深入了解wait()函数的执行过程 #include stdio.h #include sys/types.h #include sys/wait.h #include unistd.h #include stdlib.hint main() {pid_t pid;char *msg;int i;int exit_code;printf(tiger study how to get exit code\n);pid fork();if (pid 0) /* 子进程 */{msg child process is running;i 5;exit_code 37;}else if (pid 0) /* 父进程 */{exit_code 0;}else{perror(process creation failed\n);exit(1);}if (pid 0) /* 父进程 */{int status;pid_t child_pid;child_pid wait(status);printf(child process has exited, pid%d\n, child_pid);if (WIFEXITED(status)){printf(child exited with code %d\n, WEXITSTATUS(status));}else{printf(child exited abnormally\n);}}else /* 子进程 */{while (i-- 0){puts(msg);sleep(1);}}}   函数进过编译后: $ gcc wait1.c -o wait1 $ ./wait1 函数执行结果 tiger study how to get exit code  child process is running  child process is running  child process is running  child process is running  child process is running child process has exited,pid 3816 child exited with code 0   说明 父进程调用wait()函数后被挂起我们可以再开一个终端输入命令ps aux可以看到父进程的执行结果为S)直到子进程结束。子进程结束后wait()函数返回刚刚结束运行的子进程的pid,宏WEXITSTATUS获取子进程的退出码。     【注意】 如果调用 wait() 的进程没有已终止的子进程不过有一个或多个子进程仍在运行那么 wait 将阻塞到现有子进程第一个终止为止。 waitpid 函数就等待哪个进程以及是否阻塞给了我们更多控制。首先pid 参数允许我们指定想等待的进程ID值-1表示等待第一个终止的子进程。其次options 参数允许我们指定附加选项。最常用的选项是 WNOHANG它告知内核在没有已终止子进程时不要阻塞。     参考 http://www.tc5u.com/linux_unix/1635564.htm http://blog.163.com/libo_5/blog/static/15696852010324287748/ 转载于:https://www.cnblogs.com/52php/p/5684575.html
http://wiki.neutronadmin.com/news/344773/

相关文章:

  • 宁波网站建设推荐荣盛网络好网站建设职业规划
  • 网站开发招投标书网站开发课程介绍
  • 查询域名官网的是那个网站吗seo全网营销的方式
  • 微信学校网站模板做面膜的网站
  • 网站焦点图制作教程php网站模板
  • 蓟县集团网站建设龙岩市住房和城乡建设厅网站
  • 茅台镇哪一家网站做的好南宫建设局网站首页
  • 模板建站哪个平台好经典网站代码
  • wordpress回收站在哪里泰安搭建公司
  • 西安+美院+网站建设资料软件
  • 雍鑫建设集团网站设计素材网站花瓣
  • 安阳网站制作中国建设有限公司官网
  • 那个网站有帮人做图的h5简单网页代码
  • 建设一个视频网站己18网站建设网站排名
  • 辽宁朝阳网站建设公司惠州哪家做网站好
  • 顺德新网站制作网站建设 技术方案
  • 小企业网站建设怎么做好服装网站建设公司
  • 用flask做的网站有哪些怎么自己开发一个app软件
  • 合肥网站建设方案咨询萤火虫网站建设优化
  • 科站网站商业网站的建设与维护
  • 网站建设 中关村凡科网登录下载
  • 锦州网站建设多少钱百度收录网站标题
  • 工信部网站备案查询电商网站 知名案例
  • 做网站的叫什么软件大都会app下载二维码
  • 做问卷调查用哪个网站好服务器出租网站模板
  • 南县网站开发设计师找灵感的网站
  • 做国外网站什么好做电影网站违法吗
  • 云南网站建设运营西安php网站制作
  • wordpress网站换主题wordpress previous_posts_link
  • 汕头网站建设模板制作用html做女装网站