中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

西安網站外包臺州做優(yōu)化

西安網站外包,臺州做優(yōu)化,wordpress vendor,找外包公司開發(fā)app要注意什么進程的回收 1.wait 原型 pid_t wait(int *status); 功能:該函數可以阻塞等待任意子進程退出 并回收該進程的狀態(tài)。 一般用于父進程回收子進程狀態(tài)。 參數:status 進程退出時候的狀態(tài) 如果不關心其退出狀態(tài)一般用NULL表示 如果要回收進程…
進程的回收
1.wait

原型

pid_t wait(int *status);

功能:該函數可以阻塞等待任意子進程退出
??????并回收該進程的狀態(tài)。
??一般用于父進程回收子進程狀態(tài)。

參數:status?進程退出時候的狀態(tài)
??如果不關心其退出狀態(tài)一般用NULL表示
??如果要回收進程退出狀態(tài),則用WEXITSTATUS回收。

返回值:

????????成功時,wait返回終止子進程的PID。

????????失敗時,返回-1,并設置errno來指示錯誤。

關于子進程狀態(tài)的一些宏定義:

1.WIFEXITED(status)??是不是正常結束,如果返回非零值,則表示子進程正常結束了它的main函數,或者調用了exit()函數。
2.WEXITSTATUS(status)? 為真時,使用這個宏來獲取子進程的退出狀態(tài)碼。狀態(tài)碼是由main函數的返回值或者exit()函數的參數決定的。
3.WIFSIGNALED(status)?檢查子進程是否是因為接收到信號而終止的。如果返回非零值,則表示子進程是因為信號而終止。? ??
4.WTERMSIG(status) 為真時,使用這個宏來獲取導致子進程終止的信號編號。

5.WIFSTOPPED(status): 檢查子進程是否因為接收到SIGSTOP、SIGTSTPSIGTTINSIGTTOU信號而停止。如果返回非零值,則表示子進程已經停止。

6.WSTOPSIG(status): 當WIFSTOPPED(status)為真時,使用這個宏來獲取導致子進程停止的信號編號。

7.WIFCONTINUED(status): 檢查子進程是否已經從停止(stopped)狀態(tài)繼續(xù)執(zhí)行。如果返回非零值,則表示子進程已經繼續(xù)。

舉例:


int a=20;
int main(int argc, const char *argv[])
{pid_t ret =fork();if(ret>0){//printf("father is %d   pid= %d,ppid= %d \n",a,getpid(),getppid());wait(NULL);printf("after wait\n");sleep(5);}else if(0==ret){printf("child = %d pid:%d ppid:%d",a,getpid(),getppid());sleep(3);printf("child terminal\n");exit(1);}else{perror("fork");return 1;}printf("a:%d  pid:%d",a,getpid());return 0;
}

利用宏定義,判斷子進程的狀態(tài)

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
int a = 20;
int main(int argc, char *argv[])
{pid_t ret = fork();if(ret>0){//fatherprintf("father is %d   pid %d ,ppid:%d  \n",a,getpid(),getppid());int status;pid_t pid = wait(&status);if(WIFEXITED(status))// 代表子進程正常結束{//正常結束的子進程,才能獲得退出值printf("child quit values %d\n",WEXITSTATUS(status));}if(WIFSIGNALED(status))//異常結束{printf("child unnormal signal num %d\n", WTERMSIG(status));}printf("after wait, %d\n",status);}else if(0 == ret){//childprintf("child a is %d pid:%d ppid:%d\n",a,getpid(),getppid());sleep(5);printf("child terminal\n");exit(50);}else {perror("fork error\n");return 1;}printf("a is %d pid:%d\n",a,getpid());return 0;
}
2.waitpid

原型

#include <sys/types.h>
#include <sys/wait.h>pid_t waitpid(pid_t pid, int *status, int options);

參數說明:

  • pid: 子進程的PID。如果設置為?-1,則表示等待任一子進程,這與?wait?函數的行為相同。
  • status: 指向整數的指針,用于接收子進程的狀態(tài)信息。如果不需要狀態(tài)信息,可以傳遞?NULL
  • options: 指定等待行為的選項,常用的選項有:
    • WNOHANG: 如果子進程尚未終止,調用立即返回,而不是掛起等待。
    • 0:? 表示回收過程會阻塞等待

返回值:

  • 成功時,返回子進程的PID。
  • 如果子進程尚未終止(使用了?WNOHANG?選項),返回 0。
  • 失敗時,返回 -1,并設置?errno?以指示錯誤

練習:

設計一個多進程程序,用waitpid函數指定回收
其中的某個進程資源并將其狀態(tài)打印輸出。
其他的進程都以非阻塞方式進行資源回收。

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{int i = 0 ;pid_t ret[5]={0};printf("father  pid %d ,ppid:%d  \n",getpid(),getppid());for(i = 0 ;i<5;i++){ret[i] = fork();if(ret[i]>0){//father}else if(0 == ret[i]){//childprintf("child  pid:%d ppid:%d\n",getpid(),getppid());sleep(rand()%5);exit(1);}else {perror("fork error\n");return 1;}}int status;while(1){pid_t pid = waitpid(ret[2],&status, WNOHANG);if(ret[2] == pid){if(WIFEXITED(status))// 代表子進程正常結束{//正常結束的子進程,才能獲得退出值printf("child quit values %d\n",WEXITSTATUS(status));}if(WIFSIGNALED(status))//異常結束{printf("child unnormal signal num %d\n", WTERMSIG(status));}printf("father recycle success, pid :%d\n",pid);break;}else if(0 == pid){printf("子進程未結束,稍后在試\n");//usleep(1000);sleep(1);}}printf("after wait, %d\n",status);return 0;
}

exec

exec函數族在 C 語言中用于在當前進程的上下文中執(zhí)行一個新的程序。exec 函數不會創(chuàng)建新的進程,而是替換當前進程的映像為新程序的映像。這意味著進程的PID保持不變,但是執(zhí)行的程序完全改變。

exec族函數

  1. execl(const char *path, const char *arg0, ...):

    ????????加載并執(zhí)行由?path?指定的程序,arg0?是傳遞給新程序的主參數,后面可以跟隨其他參數,以?NULL?結尾。
  2. execv(const char *path, char *const argv[]):

    ? ? ? ? ? 加載并執(zhí)行由?path?指定的程序,argv?是一個以?NULL?結尾的參數數組。
  3. execle(const char *path, const char *arg0, ..., char *const envp[]):

    ? ? ? ? ? ?與?execl?類似,但允許指定一個新的環(huán)境指針數組?envp,替換當前環(huán)境。
  4. execve(const char *path, char *const argv[], char *const envp[]):

    ? ? ? ? ? ?加載并執(zhí)行由?path?指定的程序,argv?是參數數組,envp?是環(huán)境變量數組。
  5. execlp(const char *file, const char *arg0, ...):

    ? ? ? ? ? ?與?execl?類似,但在 PATH 環(huán)境變量中搜索程序?file。
  6. execvp(const char *file, char *const argv[]):

    ? ? ? ? ? ?與?execv?類似,但在 PATH 環(huán)境變量中搜索程序?file。
  7. execvpe(const char *file, char *const argv[], char *const envp[]):

    ? ? ? ? ? ?與?execve?類似,但在 PATH 環(huán)境變量中搜索程序?file,并允許指定新的環(huán)境變量數組?envp。

舉例:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[])
{//  firefox www.baidu.com //execl("/usr/bin/firefox","firefox","www.baidu.com",NULL);// env echo $PATH  ls -l --color=auto ll//execlp("ls","ls","-l","--color=auto",NULL);char *const args[]={"ls","-l","--color=auto",NULL};//execv("/bin/ls",args);//vector// pathexecvp(args[0],args);//vector+pathprintf("看見就錯了\n");exit(1);return 0;


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[])
{//  firefox www.baidu.com //execl("./aaa","aaa","1","2","3",NULL);// env echo $PATH  ls -l --color=auto ll//execlp("./aaa","aaa","1","2","3",NULL);char *const args[]={"aaa","1","2","3",NULL};//execv("./aaa",args);//vector// pathexecvp("./aaa",args);//vector+patha//如果需要都能調用成功,第一個參數都傳 路徑+文件名printf("看見就錯了\n");exit(1);return 0;
}

http://www.risenshineclean.com/news/36523.html

相關文章:

  • 好網站開發(fā)培訓夜夜草
  • php無版權企業(yè)網站管理系統(tǒng)企業(yè)網站推廣外包
  • 網站做推廣頁需要什么軟件seo收錄查詢
  • 外貿響應式網站google服務框架
  • 贛icp上饒網站建設seo網站推廣實例
  • 可以做科學模擬實驗的網站百度指數怎么查詢
  • c語言做網站賬號登錄系統(tǒng)銷售網站有哪些
  • 網站提交百度收錄怎么簡單制作一個網頁
  • 學校網站的建設目標是什么今天的熱搜榜
  • 網站開發(fā)多少錢一個網站推廣優(yōu)化價格
  • 源碼網站程序指數函數求導公式
  • 濟南品牌營銷型網站建設品牌策劃運營公司
  • 怎么編網站中央廣播電視總臺
  • 林州網站建設慈溪seo
  • 空調設備公司網站建設上海城市分站seo
  • 文化傳媒公司網站建設seo排名點擊工具
  • 如何寫好網站文案站長之家官網入口
  • 龍華做棋牌網站建設多少錢廣告聯盟接廣告
  • wordpress文章點贊旺道seo優(yōu)化軟件怎么用
  • 獨立站shopify需要費用嗎查關鍵詞排名工具app
  • 做門戶網站需要具備什么yw77731域名查詢
  • 深廣縱橫設計公司官網北京seo顧問服務
  • 公司備案查詢網站備案成都網站快速優(yōu)化排名
  • 濰坊網站建設最新報價steam交易鏈接在哪看
  • 問答網站怎么做營銷網絡營銷與直播電商專業(yè)介紹
  • 做外貿電商網站有哪個b站推廣網站
  • dede裝修網站模板申請網站域名要多少錢
  • 石巖小學網站建設品牌推廣策劃方案案例
  • 做免費推廣網站seo入門講解
  • 訪問國外網站太慢青島百度網站排名