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

wordpress添加网易云音乐盐城网站优化

wordpress添加网易云音乐,盐城网站优化,个人网页模板制作,企业电子商务网站建设策划书进程的重要函数: fork函数 了解fork函数 通过调用fork()函数#xff0c;则会产生一个新的进程。调用fork()函数的进程叫做 父进程#xff0c;产生的新进程则为子进程。 其编码过程: 1.函数功能: 函数头文件 #include sys/types.h #include unistd.h 函数…进程的重要函数: fork函数 了解fork函数 通过调用fork()函数则会产生一个新的进程。调用fork()函数的进程叫做 父进程产生的新进程则为子进程。 其编码过程: 1.函数功能: 函数头文件 #include sys/types.h #include unistd.h 函数原型 pid_t fork(void); 函数功能 创建一个子进程 函数返回值 成功:返回给父进程是子进程的pid,返回给子进程的是0 失败:返回-1,并设置errno 2.代码实例: // 创建一个子进程并打印 Hello fork #include stdio.h #include sys/types.h #include unistd.h int main() {pid_t pid fork();if(pid-1){perror(fork);return -1;}printf(Hello fork.\n);return 0; }fork创造的父子进程的特点 通过 fork() 函数创建子进程有如下特点: 父子进程并发执行子进程从 fork() 函数之后开始执行 父子进程的执行顺序由操作系统算法决定的不是由程序本身决定子进程会拷贝父进程地址空间的内容包括缓冲区、文件描述符等 代码示例: // 父子进程数据空间拷贝缓冲区的拷贝 #include stdio.h #include sys/types.h #include unistd.h int main() {// 标准IOwrite(1,write hello.,12);// 文件IO自带缓冲区fputs(fputs hello.,stdout); // 注意没有换行符,stdout的缓冲区属于行缓冲pid_t pid fork();if(pid-1){perror(fork);return -1;}printf(pid %d,Hello fork.\n,getpid());return 0; }运行结果: 1.write hello.fputs hello.pid 4711,Hello fork. 2.fputs hello.pid 4712,Hello fork.创建多个进程 在创建多个进程时,最主要的原则是由父进程统一创建统一管理不能进行递归创建 代码公示列: #include sys/types.h #include unistd.h #includestdio.h #include stdlib.h //一定要创建子进程一定要在父进程中进行 int main(){printf(hellow process\n);pid_t pid1 fork();//先创建第一个子进程if(pid1 0)//如果创建返回为0,则为子进程如果大于0,则为为父进程{printf(son1 start\n);printf(son2 end\n);}else if(pid1 -1){perror(创建失败);exit(EXIT_FAILURE);}else if(pid1 0){pid_t pid2 fork();//创建第二个子进程if(pid2 0){printf(son2 start\n);printf(son2 end\n);}else if(pid2 -1){perror(创建失败);exit(EXIT_FAILURE);}else{printf(parent start\n);printf(parent end\n);}} }题目结果: wait函数和waitpid函数 wait函数: 函数功能及引用头文件: 1.函数头文件 #include sys/types.h #include sys/wait.h2.函数原型 pid_t wait(int *wstatus);3.函数功能 让函数调用者进程进入到睡眠状态,等待子进程进入僵死状态后释放相关资源并返回4.函数参数 wstatus:保存子进程退出状态值变量的指针 *****获取具体值需要使用宏定义*****5.函数返回值 wait(): on success, returns the process ID of the terminated child; on error, -1 is returned. 成功:返回退出子进程的pid 失败:返回-12.函数代码示例(以下拿c代码来实现): using namespace std; #include iostream #include string #include cstdlib #include cstdio #include unistd.h #include sys/types.h #include sys/wait.hint main(){pid_t pid fork();if(pid -1){cout 创建失败 endl;exit(EXIT_FAILURE);}else if(pid 0){cout son start endl;sleep(2);cout son end endl; exit(1000);}else if(pid 0){int wat 0;wait(wat);} return 0; }运行结果 由此可得等待功能是多么强大它能让父进程休眠等子进程完成后父进程才开始但waitpid更强大 waitpid函数 函数功能及引用头文件 waitpid函数的功能与wait函数一样但比wait()函数功能更强大,可以理解成 wait() 底层调用waitpid()函数 1.函数头文件 #include sys/types.h #include sys/wait.h 2.函数原型 pid_t waitpid(pid_t pid, int *wstatus, int options); 3.函数参数 pid:进程id -1 可以等待任意子进程 0 等待id为pid的进程 wstatus:保存子进程退出状态值的指针 options:选项 WNOHANG 非阻塞选项 0 阻塞式与wait等同 4.函数返回值 成功 0 退出进程的pid 0 在非阻塞模式下没有进程退出 失败 -1,并设置errno函数代码: using namespace std; #include iostream #include string #include cstdlib #include cstdio #include unistd.h #include sys/types.h #include sys/wait.hint main(){pid_t pid fork();if(pid -1){cout 创建失败 endl;exit(EXIT_FAILURE);}else if(pid 0){cout son start endl;sleep(3);cout son end endl; exit(1000);}else if(pid 0){pid_t pid1 fork();if(pid1 0){cout son1 start endl;sleep(3);cout son2 end endl;exit(50);}else if(pid1 -1){cout 创建pid1失败 endl;}else if(pid1 0){int cpid 0;//waitpid(-1,NULL,0);//这是waitpid用的最多的形式while((pid waitpid(-1,NULL,0)) ! -1);//此方式可以阻挡多线程 cout parent start endl;cout parent end endl; }} return 0; }重点! 重点! 重点!: int cpid 0;while((cpidwaitpid(-1,status,WNOHANG))0);//这种方式可以阻绝任意进程是必须要掌握等待函数与进程替换有关的函数(重点) 应用场景 Linux 终端应用程序在执行命令时通过创建一个进程然后替换成对应命令的可执行程序在执行。 exec函数族(重点) : int execl(const char *pathname, const char *arg, .../* (char *) NULL */); int execlp(const char *file, const char *arg, .../* (char *) NULL */); int execle(const char *pathname, const char *arg, .../*, (char *) NULL, char *const envp[] */); int execv(const char *pathname, char *const argv[]);//最简单最方便 int execvp(const char *file, char *const argv[]);//最简单最方便 int execvpe(const char *file, char *const argv[],char *const envp[]);参数说明: path:可执行文件的路径名 file:可执行文件名可以通过PATH环境变量指定的路径 arg:参数列表以NULL结尾 argv[]:参数数组 envp[]:环境变量数组返回值: The exec() functions return only if an error has occurred. The return value is -1, and errno is set to indicate the error.其中一个示例代码(c语言): #include stdio.h #include stdlib.h #include string.h #include sys/types.h #include unistd.h #include sys/types.h #include sys/wait.h #define SIZE 10 int main(){char* param[SIZE];char command[128] { 0 };int pipefd[2];int ret pipe(pipefd);if(ret -1){perror(pipe);exit(EXIT_FAILURE);}pid_t pid fork();if(pid -1){perror(pid);exit(EXIT_FAILURE);}else if(pid 0){close(pipefd[1]);char buf[128] { 0 };size_t rtype read(pipefd[0],buf,sizeof(buf));printf(read buf:%s\n,buf);if(rtype 0){printf(1\n);close(pipefd[0]);exit(EXIT_SUCCESS);}else if(rtype -1){perror(rtype);close(pipefd[0]);exit(EXIT_FAILURE);}int index 0;//用strtok函数将命令分割开装入数组中以便进行进程替换char* cmd_name strtok(buf, );param[index] cmd_name;index;char* ret NULL;while((ret strtok(NULL, )) ! NULL){param[index] ret;index; }param[index] NULL;int ret_value execvp(cmd_name,param);//这是exec族的一个函数用来进行进行替换if(ret_value -1){perror(ret_value);exit(EXIT_FAILURE);}close(pipefd[0]);}else{close(pipefd[0]);memset(command,0,sizeof(command));printf(请输入你要实现的命令:\n);fgets(command,sizeof(command),stdin);command[strlen(command) - 1] \0;if(strcmp(command,quit) 0){printf(master\n);exit(EXIT_SUCCESS);}printf(command%s\n,command);size_t wtype write(pipefd[1],command,strlen(command));printf(wtype%ld\n,wtype);if(wtype -1){perror(wtype);close(pipefd[1]);exit(EXIT_FAILURE);}sleep(1);close(pipefd[1]);waitpid(-1,NULL,0);}}所以exec族的函数可以进行进程替换让系统响应
http://www.hkea.cn/news/14387626/

相关文章:

  • 营销单页网站制作制作网站报价
  • seo分析网站在百度怎样建网站
  • 专门做外贸的网站集安网站建设
  • 自己做的网站怎么接入银联支付互联网之光博览会参展企业
  • 池州家居网站建设怎么样保险代理公司注册条件
  • 大庆网站建设黑icp备1900邯郸哪里制作网站
  • 网站备案要多久时间湖南做电商网站需要什么条件
  • 企业网站模板带后台做招聘网站怎么办营业执照
  • 服务公司注册资金多少合适无忧seo博客
  • 滕州网站建设哪家好程序员 给老婆做网站
  • 宜昌市水利建设工程协会网站工信部网站备案怎么查询
  • 江苏省中医院网站建设男的和女的做那种短视频网站
  • 大连高新区规划建设局网站网站开发选题依据
  • 信贷网站开发深圳网站建设行业排行
  • 如何看网站是否有做网站地图wordpress 自动备份
  • 盐城市城乡建设门户网站免费的网站建造
  • 茂名企业做网站公众平台官网登录入口
  • 网站的流量是怎么回事素材图下载
  • 江门做网站的公司域名备案期间 网站访问
  • 去国外做非法网站吗注册一个5000万空壳公司要多少钱
  • 上海住房和城乡建设部网站深圳网站优化搜索
  • 光电网站建设相同网站名
  • 网站需要什么费用网站系统说明
  • 免费行情软件网站大全下载南昌市住房和城乡建设网站
  • 在哪个网站上做实验仪器比较好wordpress4.9
  • 苍南网站设计公司怎么跟电商合作去哪找
  • 放单网站建设健身器材网站源码
  • 义乌网站制作电话做产品网站费用吗
  • 做产品网站营销推广公司标志设计图片大全免费
  • 商务网站建设工程师注册安全工程师通过率