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

哪些网站做彩票预测途径上海优化外包公司排名

哪些网站做彩票预测途径,上海优化外包公司排名,西安二手房出售信息,惠阳网站建设前言: 前面我们对进程已经有了一个初步的了解与认识,现在让我们学习一下进程中一些函数的具体使用,比如exec可以执行一些指定的程序,wait / waitpid可以回收子进程,什么是孤儿进程,什么是僵尸进程&#xf…

前言:

前面我们对进程已经有了一个初步的了解与认识,现在让我们学习一下进程中一些函数的具体使用,比如exec可以执行一些指定的程序,wait / waitpid可以回收子进程,什么是孤儿进程,什么是僵尸进程,下面让我们一起对这些进行中的操作进行学习吧

目录

一、exec函数族

1.execlp:

  2.execl:

3.execvp

4.exec函数族的一般规律:

二、回收子进程

1.孤儿进程:

2 .僵尸进程:

​编辑

3.wait:

4.waitpid

 5.waitpid回收多个子进程


一、exec函数族

将当前进程的.text、.data替换为所要加载的程序的.text、.data,然后让进程从新的.text第一条指令开始执行,但进程ID不变换核丕换壳
 

1.execlp:

    int execlp(const char *file, const char *arg, ...);        借助 PATH 环境变量找寻待执行程序

        参1: 程序名

        参2: argv0

        参3: argv1

        ...: argvN

        哨兵:NULL

该函数通常用来调用系统程序。如: ls、date、cp、cat等命令。
 

#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>int main(int argc,char *argv[])
{int i;pid_t pid;        //创建子进程if(pid == -1){perror("fork error");exit(1);}else if(pid == 0){        //子进程//execlp("ls","-l","-d","-h",NULL);//错误写法/************************************/execlp("ls","ls","-l","-h",NULL);    /************************************/perror("exec error");exit(1);}else if(pid > 0){        //父进程sleep(1);printf("I'm parent : %d\n",getpid());}return 0;
}

 

 date命令的实现:

execlp("date","date",NULL);

 

  2.execl:

 int execl(const char *path, const char *arg, ...);    自己指定待执行程序路径。(路径+程序名)

#include <stdio.h>int main(int argc, char **argv)
{printf("Hello, %s!\n", argv[1]);printf("Hello, world!\n");return 0;
}

#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>int main(int argc,char *argv[])
{int i;pid_t pid;     //创建子进程if(pid == -1){perror("fork error");exit(1);}else if(pid == 0){    //子进程//execlp("ls","-l","-d","-h",NULL);//execlp("date","date",NULL);/************************************/execl("./a.out","./a.out","linux",NULL);/************************************/perror("exec error");exit(1);}else if(pid > 0){    //父进程sleep(1);printf("I'm parent : %d\n",getpid());}return 0;
}

3.execvp

加载一个进程,使用自定义环境变量env


int execvp(const char*file, const char *argv[]);

#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>int main(int argc,char *argv[])
{int i;pid_t pid;            创建子进程if(pid == -1){perror("fork error");exit(1);}else if(pid == 0){        //子进程//execlp("ls","-l","-d","-h",NULL);//execlp("date","date",NULL);//execl("./a.out","./a.out","linux",NULL);/************************************/char *argv[] = {"date",NULL};execvp("date",argv);/************************************/perror("exec error");exit(1);}else if(pid > 0){         //父进程sleep(1);printf("I'm parent : %d\n",getpid());}return 0;
}

4.exec函数族的一般规律:

        l:命令行参数列表

        p:使用PATH环境变量

        v:使用命令行参数数组

        exec函数一旦调试成功即执行新的程序,不返回。只要失败才返回,错误值-1。所以通常我们直接在exec函数调用后调用 perror()和exit()。无需if判断。· 

二、回收子进程

1.孤儿进程:

父进程死亡子进程进孤儿院

        孤儿进程:父进程先于子进程结束,则子进程成为孤儿进程,子进程的父进程成为init进程,称为init进程领养孤儿进程。
模拟孤儿进程:

#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>int main(void)
{pid_t pid;pid = fork();if (pid == 0) {while (1) {printf("I am child, my parent pid = %d\n", getppid());sleep(1);}} else if (pid > 0) {printf("I am parent, my pid is = %d\n", getpid());sleep(9);printf("------------parent going to die------------\n");} else {perror("fork");return 1;}return 0;
}

 查看进程状态:ps ajx

 进程孤儿院:

  1   2035   2035   2035 ?            -1 Ss    1001   0:00 /lib/systemd/systemd --user

 解决方法:

                 杀死子进程:     kill -9 4871

2 .僵尸进程:

子进程死亡,父进程一直不管 

        僵尸进程:进程终止,父进程尚未回收,子进程残留资源(PCB)存放于内核中,变成僵尸(zombie)进程。(死亡以后没有回收)

        特别注意,僵尸进程是不能使用kill命令清除掉的。因为kill命令只是用来终止进程的,而僵尸进程已经终止。

模拟僵尸进程:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>int main(void)
{pid_t pid;pid = fork();if (pid == 0) {printf("---child, my parent= %d, going to sleep 10s\n", getppid());sleep(10);printf("-------------child die--------------\n");} else if (pid > 0) {while (1) {printf("I am parent, pid = %d, myson = %d\n", getpid(), pid);sleep(1);}} else {perror("fork");return 1;}return 0;
}

  查看进程状态:ps ajx

 解决方法:

        杀死父进程:   kill -9 4770

*3.wait:

    wait函数:    回收子进程退出资源, 阻塞回收任意一个。

    pid_t wait(int *status)

    

    参数:(传出) 回收进程的状态。

    返回值:成功: 回收进程的pid

                   失败: -1, errno

    函数作用1:    阻塞等待子进程退出

    函数作用2:    清理子进程残留在内核的 pcb 资源

    函数作用3:    通过传出参数,得到子进程结束状态

    
    获取子进程正常终止值

        WIFEXITED(status) --》 为真 --》调用 WEXITSTATUS(status) --》 得到 子进程 退出值。

    获取导致子进程异常终止信号

        WIFSIGNALED(status) --》 为真 --》调用 WTERMSIG(status) --》 得到 导致子进程异常终止的信号编号。

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>int main(void)
{pid_t pid, wpid;int status;pid = fork();if (pid == 0) {printf("---child, my id= %d, going to sleep 10s\n", getpid());sleep(10);printf("-------------child die--------------\n");return 73;} else if (pid > 0) {//wpid = wait(NULL);          // 不关心子进程结束原因wpid = wait(&status);       // 如果子进程未终止,父进程阻塞在这个函数上if (wpid == -1) {perror("wait error");exit(1);}if (WIFEXITED(status)) {        //为真,说明子进程正常终止. printf("child exit with %d\n", WEXITSTATUS(status));}if (WIFSIGNALED(status)) {      //为真,说明子进程是被信号终止.printf("child kill with signal %d\n", WTERMSIG(status));}printf("------------parent wait finish: %d\n", wpid);} else {perror("fork");return 1;}return 0;
}

正常终止:

被信号终止:

*4.waitpid

waitpid函数:    指定某一个进程进行回收。可以设置非阻塞。          

    waitpid(-1, &status, 0) == wait(&status);

    pid_t waitpid(pid_t pid, int *status, int options)

    

参数:
        pid:指定回收某一个子进程pid

            > 0: 待回收的子进程pid

            -1:任意子进程

            0:同组的子进程。

        status:(传出) 回收进程的状态。

        options:WNOHANG 指定回收方式为,非阻塞。

  

 返回值:

        > 0 : 表成功回收的子进程 pid

        0 : 函数调用时, 参3 指定了WNOHANG, 并且,没有子进程结束。

        -1: 失败。errno

回收任意子进程:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/wait.h>int main(int argc,char *argv[])
{int i;pid_t pid,wpid;for(i = 0;i < 5;i++){if(fork()==0)       //循环期间,子进程不forkbreak;}if(i == 5){           //父进程//wait(NULL);//一次wait/waitpid函数调用,只能回收一个子进程/*****************************************/wpid = waitpid(-1,NULL,WNOHANG);//回收任意子进程,没有结束的子进程,父进程直接返回0/****************************************/if(wpid == -1){perror("waitpid error");exit(1);}printf("I'm parent ,wait a child finish :%d\n",wpid);}else{            //子进程,从break跳出sleep(i);printf("I'm %dth child\n",i+1);}return 0;
}


回收指定进程:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/wait.h>int main(int argc,char *argv[])
{int i;pid_t pid,wpid,tmpid;for(i = 0;i < 5;i++){pid = fork();if(pid == 0){       //循环期间,子进程不forkbreak;}if(i == 2){tmpid = pid;printf("*************pid= %d***************\n",pid);}}if(i == 5){           //父进程,从表达式2跳出sleep(5);		  //设置睡眠,等所有子进程结束后再回收//wait(NULL);	   //一次wait/waitpid函数调用,只能回收一个子进程//wpid = waitpid(-1,NULL,WNOHANG);     //回收任意子进程,没有结束的子进程,父进程直接返回0printf("I am parent , before waitpid , pid = %d\n",tmpid);/********将前面sleep(5)屏蔽***************///wpid = waitpid(tmpid,NULL,0);         //指定一个进程回收,阻塞回收/****************************************//*****************************************/wpid = waitpid(tmpid,NULL,WNOHANG);     //指定一个进程回收,不阻塞/****************************************/if(wpid == -1){perror("waitpid error");exit(1);}printf("I'm parent ,wait a child finish :%d\n",wpid);	//wpid回收的是真正的子进程id}else{            //子进程,从break跳出sleep(i);printf("I'm %dth child,pid = %d\n",i+1,getpid());}return 0;
}

注意:

        一次wait/waitpid调用只能回收一个子进程,无法回收他孙子辈的进程,多次清理需要while

 5.waitpid回收多个子进程

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/wait.h>int main(int argc,char *argv[])
{int i;pid_t pid,wpid;for(i = 0;i < 5;i++){pid = fork();if(pid == 0){       //循环期间,子进程不forkbreak;}}if(i == 5){    //父进程/**********使用阻塞回收子进程********/while((wpid = waitpid(-1,NULL,0))){printf("wait child %d\n",wpid);}/***********************************/}else{        //子进程sleep(i);printf("I'm %dth child ,pid =%d\n",i+1,getpid());}return 0;
}

结束一个回收一个

之后返回-1,表示没有失败了

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/wait.h>int main(int argc,char *argv[])
{int i;pid_t pid,wpid;for(i = 0;i < 5;i++){pid = fork();if(pid == 0){       //循环期间,子进程不forkbreak;}}if(i == 5){/*********使用阻塞回收子进程***********//*while((wpid = waitpid(-1,NULL,0))){printf("wait child %d\n",wpid);}*//***********************************//*******使用非阻塞方式回收子进程******/while((wpid = waitpid(-1,NULL,WNOHANG)) != -1){if(wpid > 0){	printf("wait child %d\n",wpid);}else if(wpid == 0){sleep(1);continue;}/************************************/}}else{sleep(i);printf("I'm %dth child ,pid =%d\n",i+1,getpid());}return 0;
}


文章转载自:
http://lazarus.rzgp.cn
http://crampon.rzgp.cn
http://revivalist.rzgp.cn
http://akashi.rzgp.cn
http://balky.rzgp.cn
http://eupepsia.rzgp.cn
http://emic.rzgp.cn
http://hydrophanous.rzgp.cn
http://cargoboat.rzgp.cn
http://strapwork.rzgp.cn
http://semiology.rzgp.cn
http://theosophic.rzgp.cn
http://vesiculous.rzgp.cn
http://maranta.rzgp.cn
http://bdsc.rzgp.cn
http://isometrical.rzgp.cn
http://leucin.rzgp.cn
http://bugseed.rzgp.cn
http://rectangularity.rzgp.cn
http://cheerless.rzgp.cn
http://ficelle.rzgp.cn
http://maledictory.rzgp.cn
http://processing.rzgp.cn
http://sidebone.rzgp.cn
http://gallate.rzgp.cn
http://sugh.rzgp.cn
http://likely.rzgp.cn
http://spasmodically.rzgp.cn
http://jd.rzgp.cn
http://ruminator.rzgp.cn
http://technocomplex.rzgp.cn
http://incubatory.rzgp.cn
http://documentary.rzgp.cn
http://belletrist.rzgp.cn
http://epigram.rzgp.cn
http://quiescence.rzgp.cn
http://numismatist.rzgp.cn
http://proser.rzgp.cn
http://imperfective.rzgp.cn
http://denver.rzgp.cn
http://evenhanded.rzgp.cn
http://usbeg.rzgp.cn
http://spalpeen.rzgp.cn
http://furculum.rzgp.cn
http://cabtrack.rzgp.cn
http://letting.rzgp.cn
http://chesterfieldian.rzgp.cn
http://suiting.rzgp.cn
http://immortalization.rzgp.cn
http://mighty.rzgp.cn
http://grounder.rzgp.cn
http://paternalist.rzgp.cn
http://sedimentologic.rzgp.cn
http://logically.rzgp.cn
http://pcte.rzgp.cn
http://birmingham.rzgp.cn
http://ann.rzgp.cn
http://fluidness.rzgp.cn
http://rumor.rzgp.cn
http://misapprehension.rzgp.cn
http://belgium.rzgp.cn
http://crystallise.rzgp.cn
http://uneloquent.rzgp.cn
http://attune.rzgp.cn
http://disuse.rzgp.cn
http://kaifeng.rzgp.cn
http://liquid.rzgp.cn
http://breadbox.rzgp.cn
http://uvdicon.rzgp.cn
http://seecatch.rzgp.cn
http://snakey.rzgp.cn
http://libel.rzgp.cn
http://kilometrage.rzgp.cn
http://hydromedusa.rzgp.cn
http://colligability.rzgp.cn
http://stepladder.rzgp.cn
http://musicianly.rzgp.cn
http://coleorhiza.rzgp.cn
http://dumfriesshire.rzgp.cn
http://whacking.rzgp.cn
http://mott.rzgp.cn
http://cesura.rzgp.cn
http://imperception.rzgp.cn
http://tensile.rzgp.cn
http://civitan.rzgp.cn
http://find.rzgp.cn
http://barat.rzgp.cn
http://blacksnake.rzgp.cn
http://humorlessness.rzgp.cn
http://decolourant.rzgp.cn
http://spirochetal.rzgp.cn
http://ultraclean.rzgp.cn
http://diskcomp.rzgp.cn
http://pyrographer.rzgp.cn
http://shacklebone.rzgp.cn
http://minnesinger.rzgp.cn
http://astrosphere.rzgp.cn
http://officinal.rzgp.cn
http://shrank.rzgp.cn
http://sakyamuni.rzgp.cn
http://www.dt0577.cn/news/99202.html

相关文章:

  • wordpress链接版权seo网站推广助理招聘
  • 网站常用的一种js的图片幻灯片特效代码网页设计实训报告
  • 网站建设 镇江网站优化推广费用
  • 网站维护的要求百度搜索风云榜人物
  • 企业网站怎么做推广常见的网络营销工具有哪些
  • 做乒乓球网站的图片人工智能培训心得体会
  • 怎么邀约客户做网站上海优化关键词的公司
  • 郑州哪里能做个人网页东莞seo建站
  • 网站建设主流开发语言培训心得体会怎么写
  • 重庆百度网站快速排名石家庄seo
  • 简要描述网站建设的基本步骤海外市场推广做什么的
  • 网站建设需要学习哪些网站推广的方法
  • 知名网站建设加盟合作微平台推广
  • 一个网站怎么绑定很多个域名今天的新闻发布会
  • 为什么网站在本地看没问题上传之后没有内容呢?百度怎么推广自己的产品
  • 甘肃省铁路投资建设集团有限公司网站网站内链优化
  • 外贸网站建设的好处数据分析师培训
  • 网站建设开发报价单仿站定制模板建站
  • 中企动力企业邮箱下载短视频优化
  • 大连市社会信用体系建设网站海外seo
  • 网红营销也称为360优化大师官方下载
  • 做响应式网站设计推广软件哪个好
  • 网页设计与制作实例教程惠州自动seo
  • 网站开发毕业设计文献综述推广放单平台
  • 如何做自己的加盟网站seo新人怎么发外链
  • 网站网警备案流程合肥seo外包平台
  • 用织梦做的网站好还是cms制作自己的网站
  • 网站建设有哪些南昌网站优化公司
  • 计算机网站建设 是什么意思如何进行网络营销
  • 零基础月做网站多久快速提高排名