亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1346 | 回復: 0
打印 上一主題 下一主題

linux下常用linux c函數(shù) [復制鏈接]

論壇徽章:
0
跳轉到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2009-11-25 13:57 |只看該作者 |倒序瀏覽
1.     進程ID為0的進程通常是調度進程,常常被稱為交換進程
進程ID為1的進程通常是init進程,在自舉過程結束時由內核調用
進程ID為2的進程頁守護進程,負責支持虛擬存儲系統(tǒng)的分頁操作
2.     pid_t getpid( void ); 返回值:調用進程的進程ID     #include
3.     pid_t getppid( void ); 返回值:調用進程的父進程ID   
4.     uid_t getuid( void ); 返回值:調用進程的實際用戶ID
5.     uid_t geteuid( void ); 返回值:調用進程的有效用戶ID
6.     gid_t getgid( void ); 返回值:調用進程的實際組ID
7.     gid_t getegid( void ); 返回值:調用進程的有效組ID
8.     pid_t fork( void );創(chuàng)建子進程,返回值:子進程返回0,父進程返回子進程ID,出錯-1
9.     #include pid_t wait(int *statloc);//statloc 保存進程終止狀態(tài)的指針
10.     #includepid_t waitpid(pid_t pid,int *statloc,int options);
pid ==-1 等待任一子進程
pid >0 等待其子進程ID與pid相等的子進程
pid == 0 等待其組ID等于調用進程組ID的任一子進程
pid  int setuid(uid_t uid); 設置實際實際用戶ID和有效用戶ID;
int setgid(gid_t gid); 設置實際組ID和有效組ID;成功返回0,錯誤-1
12.#includeint system(const char *cmdstring)
system返回值如下            
-1出現(xiàn)錯誤   
    0調用成功但是沒有出現(xiàn)子進程   
    >0   成功退出的子進程的id
(二)線程
1. #include int pthread_equal(pthread_t tid1, pthread_t tid2);
//相等返回非0,否則返回0
2. pthread_t pthread_self(void);返回調用線程的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),以恢復資源。成功返回0,否則返回錯誤編號
6. int pthread_cancel(pthread_t tid);
//請求取消同一進程中的其他線程;成功返回0,否則返回錯誤編號
7. void pthread_cleanup_push(void (*rtn)(void *), void *arg);
    //建立線程清理處理程序
8. void pthread_cleanup_pop(int execute);//調用建立的清理處理程序
9. int pthread_detach(pthread_t tid);//使線程進入分離狀態(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);
//若有調用malloc動態(tà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);//釋放資源,在釋放內存之前使用
成功返回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)檎,如果在給定的時間內條件不能滿足,那么會生成一個代表出錯碼的返回變量 ;成功返回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);//釋放內存空間(動態(tài)分配時調用)
成功返回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);
  //設置分離狀態(tài) PTHREAD_CREATE_DETACHED:以分離狀態(tài)啟動線程
  PTHREAD_CREATE_JOINABLE:正常啟動線程,應用程序可以獲取線程的終止狀態(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)
//設置新建線程的棧位置 ;成功返回0,否則返回錯誤編號
(三)消息隊列
1.每個隊列都有一個msqid_ds結構與之相關聯(lián):
    struct msqid_ds{
      struct ipc_perm msg_perm;
          msgqnum_t msg_qnum; //消息的數(shù)量
      msglen_t msg_qbytes; //最大消息的長度
      pid_t msg_lspid;   //最后一個發(fā)送到消息隊列的進程ID
      pid_t msg_lrpid;   //最后一個讀取消息的進程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; //權限
      。
      。
  }
2.#include  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結構,并將它放在buf指向的結構

IPC_SET:按由buf指向結構中的值,設置與此隊列相關結構中的下列四個字
段:msg_perm.uid,msg_perm.gid,msg_perm.mode和msg_qbytes.此命令只有下列兩種進程才能執(zhí)行(1)其
有效用戶ID等于msg_perm.cuid或msg_perm.uid;(2)具有超級用戶特權的進程
  IPC_RMID:從系統(tǒng)中刪除消息隊列以及仍在該隊列中的所有數(shù)據(jù)。
成功返回0,失敗返回-1
4.int msgsnd(int msqid, const void *ptr, size_t nbytes, int flag)//發(fā)送消息到消息隊列中
成功返回0, 不成功返回-1并設置errno,錯誤碼:
EACCES   對調用程序來說,調用被否定
EAGAIN   操作會阻塞進程,但(msgflg & IPC_NOWAIT) != 0
EIDRM     msqid已經(jīng)從系統(tǒng)中刪除了
EINTR     函數(shù)被信號中斷
EINVAL     參數(shù)msqid無效,消息類型0 返回隊列中消息類型為type的第一個消息
  type. int semget(key_t key, int nsems, int flag);//創(chuàng)建信號量
成功返回一個對應于信號量集標識符的非負整數(shù),不成功返回-1并設置errno,錯誤碼:
EACCES   存在key的信號量,但沒有授予權限
EEXIST   存在key的信號量,但是
    ( (semflg & IPC_CREATE) && (semflg & IPC_EXCL) ) != 0
EINVAL   nsems <= 0或者大于系統(tǒng)的限制,或者nsems與信號量集的大小不符
ENOENT   不存在key的信號量,而且(semflg & IPC_CTEATE) == 0
ENOSPC   要超出系統(tǒng)范圍內對信號量的限制了
功能:
函數(shù)返回與參數(shù)key相關的信號量集標識符。
如果鍵值為IPC_PRIVATE,或者semflg&IPC_CREAT非零且沒有信號量集或標識符關聯(lián)于key,那么函數(shù)就創(chuàng)建標識符及與之相關的信號量集。
參數(shù)nsems指定了集合中信號量元素的個數(shù),可用0到nsems-1的整數(shù)來引用信號量集合中的單個信號量元素。
參數(shù)semflg指定信號量集的優(yōu)先級,權限的設置與文件權限設置相同,并可以通過semclt來修改權限值,在使用信號量元素之前,應該用semctl對其進行初始化。
注意:
函數(shù)如果試圖創(chuàng)
轉載地址http://www.diybl.com/course/6_system/linux/Linuxjs/2008911/141909.html
               
               
               

本文來自ChinaUnix博客,如果查看原文請點:http://blog.chinaunix.net/u3/104213/showart_2103592.html
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉載本站內容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP