乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      linux下常用linux c函數(shù)--lhzw2001的筆記

       SkySeraph 2010-07-25
      linux下常用linux c函數(shù)
      1.     進(jìn)程ID為0的進(jìn)程通常是調(diào)度進(jìn)程,常常被稱為交換進(jìn)程
      進(jìn)程ID為1的進(jìn)程通常是init進(jìn)程,在自舉過程結(jié)束時由內(nèi)核調(diào)用
      進(jìn)程ID為2的進(jìn)程頁守護(hù)進(jìn)程,負(fù)責(zé)支持虛擬存儲系統(tǒng)的分頁操作
      2.     pid_t getpid( void ); 返回值:調(diào)用進(jìn)程的進(jìn)程ID     #i nclude <unistd.h>
      3.     pid_t getppid( void ); 返回值:調(diào)用進(jìn)程的父進(jìn)程ID  
      4.     uid_t getuid( void ); 返回值:調(diào)用進(jìn)程的實際用戶ID
      5.     uid_t geteuid( void ); 返回值:調(diào)用進(jìn)程的有效用戶ID
      6.     gid_t getgid( void ); 返回值:調(diào)用進(jìn)程的實際組ID
      7.     gid_t getegid( void ); 返回值:調(diào)用進(jìn)程的有效組ID
      8.     pid_t fork( void );創(chuàng)建子進(jìn)程,返回值:子進(jìn)程返回0,父進(jìn)程返回子進(jìn)程ID,出錯-1
      9.     #i nclude<sys/wait.h> pid_t wait(int *statloc);//statloc 保存進(jìn)程終止?fàn)顟B(tài)的指針
      10.     #i nclude<sys/wait.h>pid_t waitpid(pid_t pid,int *statloc,int options);
      pid ==-1 等待任一子進(jìn)程
      pid >0 等待其子進(jìn)程ID與pid相等的子進(jìn)程
      pid == 0 等待其組ID等于調(diào)用進(jìn)程組ID的任一子進(jìn)程
      pid <-1 等待其組ID等于pid絕對值的任一子進(jìn)程
      options:
      WCONTINUED 若實現(xiàn)支持作業(yè)控制,那么由pid指定的任一子進(jìn)程在暫停后已經(jīng)繼續(xù),但其狀態(tài)尚未報告,則返回其狀態(tài)
      WNOHANG 若由pid指定的子進(jìn)程并不是立即可用的,則waitpid阻塞,此時其返回0
      WUNTRACED 若實現(xiàn)支持作業(yè)控制,而由pid指定的任一子進(jìn)程已處于暫停狀態(tài),并且其狀態(tài)自暫停以來還未報告過,則返回其狀態(tài)
      11.#i nclude<unistd.h> int setuid(uid_t uid); 設(shè)置實際實際用戶ID和有效用戶ID;
      int setgid(gid_t gid); 設(shè)置實際組ID和有效組ID;成功返回0,錯誤-1
      12.#i nclude<stdlib.h>int system(const char *cmdstring)
      system返回值如下            
      -1出現(xiàn)錯誤  
          0調(diào)用成功但是沒有出現(xiàn)子進(jìn)程  
          >0   成功退出的子進(jìn)程的id


      (二)線程


      1. #i nclude<thread.h> int pthread_equal(pthread_t tid1, pthread_t tid2);
      //相等返回非0,否則返回0
      2. pthread_t pthread_self(void);返回調(diào)用線程的ID
      3. int pthread_create(pthread_t *restrict tidp,
        const pthread_attr_t *restrict attr, void *(*start_rtn)(void), void *restrict arg) ;
      創(chuàng)建線程:成功返回0,否則返回錯誤編號
      4. void pthread_exit(void *rval_ptr);//終止線程
      5. int pthread_join(pthread_t thread, void **rval_ptr);
      //自動線程置于分離狀態(tài),以恢復(fù)資源。成功返回0,否則返回錯誤編號
      6. int pthread_cancel(pthread_t tid);
      //請求取消同一進(jìn)程中的其他線程;成功返回0,否則返回錯誤編號
      7. void pthread_cleanup_push(void (*rtn)(void *), void *arg);
          //建立線程清理處理程序
      8. void pthread_cleanup_pop(int execute);//調(diào)用建立的清理處理程序
      9. int pthread_detach(pthread_t tid);//使線程進(jìn)入分離狀態(tài),已分離也不出錯
      10.int pthread_mutex_init(pthread_mutex_t *restrict mutex,
        const pthread_nutexattr_t *restrict attr)//初始化互斥量;成功0,失敗返回錯誤編號
      11.int pthread_mutex_destroy(pthread_mutex_t *mutex);
      //若有調(diào)用malloc動態(tài)分配內(nèi)存則用該函數(shù)釋放;成功0,失敗返回錯誤編號
      12.int pthread_mutex_lock(pthread_mutex_t *mutex);//鎖住互斥量
        int pthread_mutex_trylock(pthread_mutex_t *mutex);//嘗試上鎖
        int pthread_mutex_unlock(pthread_mutex_t *mutex);//解鎖
        成功返回0,否則返回錯誤編號
      13.int pthread_rwlock_init(pthread_rwlock_t *restrict rwlock, const pthread_rwlockattr_t *restrict attr)//初始化讀寫鎖
        int pthread_rwlock_destroy(pthread_rwlock_t *rwlock);//釋放資源,在釋放內(nèi)存之前使用
      成功返回0,否則返回錯誤編號
      14.int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);//在讀模式下鎖定讀寫鎖
        int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);//在寫模式下鎖定讀寫鎖
        int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);//鎖住讀寫鎖
      15.int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);//嘗試在讀模式下鎖定讀寫鎖
        int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock);//嘗試在寫模式下鎖定讀寫鎖
      成功返回0,否則返回錯誤編號
      16.int pthread_cond_init(pthread_cond_t *restrict cond, pthread_condattr_t * restrict attr)
      //初始化條件變量
        int pthread_cond_destroy(pthread_cond_t *cond);//去除初始化條件變量
      成功返回0,否則返回錯誤編號
      17.int pthread_cond_wait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex)
        int pthread_cond_wait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex,
        const struct timespec *restrict timeout);
        //等待條件變?yōu)檎?,如果在給定的時間內(nèi)條件不能滿足,那么會生成一個代表出錯碼的返回變量 ;成功返回0,錯誤返回錯誤編號
      18.int pthread_cond_signal(pthread_cond_t *cond);//喚醒等待該條件的某個線程
        int pthread_cond_broadcast(pthread_cond_t *cond)//喚醒等待該條件的所有線程
      19.int pthread_attr_init(pthread_attr_t *attr);//初始化線程屬性
        int pthread_attr_destroy(pthread_attr_t *attr);//釋放內(nèi)存空間(動態(tài)分配時調(diào)用)
      成功返回0,否則返回錯誤編號
      20.int pthread_attr_getdetachstate(const pthread_attr_t *restrict attr, int *detachstate);
      //獲取線程的分離狀態(tài)
        int pthread_attr_setdetachstate(const pthread_attr_t *restrict attr, int detachstate);
        //設(shè)置分離狀態(tài) PTHREAD_CREATE_DETACHED:以分離狀態(tài)啟動線程
        PTHREAD_CREATE_JOINABLE:正常啟動線程,應(yīng)用程序可以獲取線程的終止?fàn)顟B(tài)
          成功返回0,否則返回錯誤編號
      21.int pthread_attr_getstack(const pthread_attr_t *restrict attr,void **restrict stackaddr, size_t *restrict stacksize);//獲取線程的棧位置
      int pthread_attr_setstack(const pthread_attr_t *attr, void *stackaddr, size_t *stacksize)
      //設(shè)置新建線程的棧位置 ;成功返回0,否則返回錯誤編號


      (三)消息隊列


      1.每個隊列都有一個msqid_ds結(jié)構(gòu)與之相關(guān)聯(lián):
          struct msqid_ds{
            struct ipc_perm msg_perm;
                msgqnum_t msg_qnum; //消息的數(shù)量
            msglen_t msg_qbytes; //最大消息的長度
            pid_t msg_lspid;   //最后一個發(fā)送到消息隊列的進(jìn)程ID
            pid_t msg_lrpid;   //最后一個讀取消息的進(jìn)程ID
            time_t msg_stime;   //最后一次發(fā)送到消息隊列的時間
            time_t msg_rtime;   //最后一次讀取消息的時間
            time_t msg_ctime; //最后一次改變的時間
            。
            。
            。
        };
        struct ipc_perm{
            uid_t uid;//擁有者有效的用戶ID
            gid_t gid;//擁有者有效的組ID
            uid_t cuid;//創(chuàng)建者有效的用戶ID
            uid_t cgid;//創(chuàng)建者有效的組ID
            mode_t mode; //權(quán)限
            。
            。
        }
      2.#i nclude <sys/msg.h> int msgget(key_t key, int flag);
      //打開一個現(xiàn)存的隊列或創(chuàng)建一個新隊列;成功返回0,出錯返回-1
      3.int msgctl(int msqid, int cmd, struct msqid_ds *buf);//對消息隊列執(zhí)行多種操作
      cmd 可選:
      IPC_STAT 取此消息隊列的msqid_ds結(jié)構(gòu),并將它放在buf指向的結(jié)構(gòu)
        IPC_SET:按由buf指向結(jié)構(gòu)中的值,設(shè)置與此隊列相關(guān)結(jié)構(gòu)中的下列四個字段:msg_perm.uid,msg_perm.gid,msg_perm.mode和msg_qbytes.此命令只有下列兩種進(jìn)程才能執(zhí)行(1)其有效用戶ID等于msg_perm.cuid或msg_perm.uid;(2)具有超級用戶特權(quán)的進(jìn)程
        IPC_RMID:從系統(tǒng)中刪除消息隊列以及仍在該隊列中的所有數(shù)據(jù)。
      成功返回0,失敗返回-1
      4.int msgsnd(int msqid, const void *ptr, size_t nbytes, int flag)//發(fā)送消息到消息隊列中
      成功返回0, 不成功返回-1并設(shè)置errno,錯誤碼:
      EACCES   對調(diào)用程序來說,調(diào)用被否定
      EAGAIN   操作會阻塞進(jìn)程,但(msgflg & IPC_NOWAIT) != 0
      EIDRM     msqid已經(jīng)從系統(tǒng)中刪除了
      EINTR     函數(shù)被信號中斷
      EINVAL     參數(shù)msqid無效,消息類型<1,或者msgsz越界了
      flag可以指定為IPC_NOWAIT 則不會阻塞直接返回EAGAIN
      注:參數(shù)msgp指向用戶定義的緩沖區(qū),他是如下的結(jié)構(gòu)
      struct mymsg
      {
      long mtypes;     消息類型
      char *mtext;   消息文本
      }mymsg_t
      5.ssize_t msgrcv(int msqid, void *ptr, size_t nbytes, long type, int flag);//讀取消息
      成功則返回消息的數(shù)據(jù)部分的長度,出錯則返回-1
      type: type==0返回隊列中的第一個消息
        type>0 返回隊列中消息類型為type的第一個消息
        type<0返回隊列中消息類型值小于或等于type絕對值的消息(多個取類型值最小的)


      (四) 信號量


      1. 內(nèi)核為每個信號量集合設(shè)置了一個semid_ds結(jié)構(gòu):
        struct demid_ds{
          struct ipc_perm sem_perm;
          unsigned short sem_nsems; //信號量的個數(shù)
          time_t sem_otime; //上一次semop的時間
          time_t sem_ctime;//上一次change的時間
          。
          。
       };
      2#i nclude<sys/sem.h>. int semget(key_t key, int nsems, int flag);//創(chuàng)建信號量
      成功返回一個對應(yīng)于信號量集標(biāo)識符的非負(fù)整數(shù),不成功返回-1并設(shè)置errno,錯誤碼:
      EACCES   存在key的信號量,但沒有授予權(quán)限
      EEXIST   存在key的信號量,但是
          ( (semflg & IPC_CREATE) && (semflg & IPC_EXCL) ) != 0
      EINVAL   nsems <= 0或者大于系統(tǒng)的限制,或者nsems與信號量集的大小不符
      ENOENT   不存在key的信號量,而且(semflg & IPC_CTEATE) == 0
      ENOSPC   要超出系統(tǒng)范圍內(nèi)對信號量的限制了
      功能:
      函數(shù)返回與參數(shù)key相關(guān)的信號量集標(biāo)識符。
      如果鍵值為IPC_PRIVATE,或者semflg&IPC_CREAT非零且沒有信號量集或標(biāo)識符關(guān)聯(lián)于key,那么函數(shù)就創(chuàng)建標(biāo)識符及與之相關(guān)的信號量集。
      參數(shù)nsems指定了集合中信號量元素的個數(shù),可用0到nsems-1的整數(shù)來引用信號量集合中的單個信號量元素。
      參數(shù)semflg指定信號量集的優(yōu)先級,權(quán)限的設(shè)置與文件權(quán)限設(shè)置相同,并可以通過semclt來修改權(quán)限值,在使用信號量元素之前,應(yīng)該用semctl對其進(jìn)行初始化。

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多