青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

posts - 297,  comments - 15,  trackbacks - 0
process進(jìn)程 and thread
獲取當(dāng)前進(jìn)程getpid(),父進(jìn)程getppid(),當(dāng)前用戶ID,getuid(), geteuid(),組ID,getgid(),getegid(), all need head file <unistd.h>
getlogin()返回登錄用戶名
example:
#include <iostream.h>
#include <unistd.h> //getpid() getppid()
int main()
{
cout<<getpid()<<endl; //current process ID
cout<<getppid()<<endl; //parent process ID
cout<<getgid()<<endl; //group process ID
cout<<getegid()<<endl; //effective group process ID
cout<<getuid()<<endl; //user process ID
cout<<geteuid()<<endl; //effective user process ID
cout<<getlogin()<<endl; //getlogin() return the login user name
                                                                            
return 0;
}

獲取登錄用戶的個(gè)人信息,如用戶名,當(dāng)前目錄,用戶ID,組ID等,need function struct passwd * getpwnam(const char *name)
如下面的例子:
/*
 * getname.c - Get login names
 */
#include <stdio.h>
#include <stdlib.h>//exit()
#include <unistd.h>//getlogin()
#include <pwd.h> //getpwnam()
                                                                                
int main(void)
{
        char *login;
        struct passwd *pentry;
                                                                                
        /* Get the login name */
        if((login = getlogin()) == NULL) { /* oops */
        perror("getlogin");
        exit(EXIT_FAILURE);
        }
                                                                                
        /* Get the password entry for login */
        if((pentry = getpwnam(login)) == NULL) {
        perror("getpwnam");
       exit(EXIT_FAILURE);
        }
                                                                                
        /* Display the password entry */
        printf("user name: %s\n", pentry->pw_name);
        printf("UID : %d\n", pentry->pw_uid);
        printf("GID : %d\n", pentry->pw_gid);
        printf("gecos : %s\n", pentry->pw_gecos);
        printf("home dir : %s\n", pentry->pw_dir);
        printf("shell : %s\n", pentry->pw_shell);
                                                                                
        exit(EXIT_SUCCESS);
}

system()
如果沒(méi)有找到/bin/sh則返回127,成功返回0,出錯(cuò)返回-1
example:
/*
 * system.c - Demonstrate the system() call
 */
#include <stdio.h>
#include <stdlib.h>
                                                                                
int main(void)
{
        int retval;
                                                                                
        retval = system("ls -l");
                                                                                
        if(retval == 127) {
                fprintf(stderr, "/bin/sh not available\n");
                exit(127);
        } else if(retval == -1) {
                perror("system");
                exit(EXIT_FAILURE);
        } else if(retval != 0) {
                fprintf(stderr, "command returned %d\n", retval);
                perror("ls");
        } else {
                puts("command successfully executed");
}
        exit(EXIT_SUCCESS);
}

fork調(diào)用創(chuàng)建一個(gè)新進(jìn)程
#include <unistd.h>

pid_t fork(void);

Description
fork() creates a child process that differs from the parent process only in its PID and PPID,
return value:
On success, the PID of the child process is returned in the parent's thread of execution, and a 0 is returned in the child's thread of execution. On failure, a -1 will be returned in the parent's context, no child process will be created, and errno will be set appropriately.執(zhí)行成功,就向父進(jìn)程返回子進(jìn)程的PID,并向子進(jìn)程返回0,只調(diào)用一次fork,它會(huì)返回兩次

example:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
                                                                                
int main(void)
{
    pid_t child;
                                                                                
    if((child = fork()) == -1) {
        perror("fork");
        exit(EXIT_FAILURE);
    } else if(child == 0) {
        puts("in child");
        printf("\tchild pid = %d\n", getpid());
        printf("\tchild ppid = %d\n", getppid());
        exit(EXIT_SUCCESS);
    } else {
        puts("in parent");
        printf("\tparent pid = %d\n", getpid());
        printf("\tparent ppid = %d\n", getppid());
    }
    exit(EXIT_SUCCESS);
}

exec()函數(shù)族
exec用被執(zhí)行的程序完全替換了調(diào)用進(jìn)程的映像。exec啟動(dòng)一個(gè)新程序,替換原有的進(jìn)程
execl, execlp, execle, execv, execvp - execute a file
Synopsis
#include <unistd.h>

extern char **environ;

int execl(const char *path, const char *arg, ...);
int execlp(const char *file, const char *arg, ...);
int execle(const char *path, const char *arg,
..., char * const envp[]);
int execve    (const char *path, char *const argv[]);
int execvp(const char *file, char *const argv[]);
以上的函數(shù)都必須以NULL結(jié)束

example:
/*
 * execve.c - Illustrate execve
 */
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
                                                                                
int main(void)
{
    char *argv[] = {"/bin/ls", NULL};
                                                                                
    if(execve("/bin/ls", argv, NULL) == -1) {
        perror("execve");
        exit(EXIT_FAILURE);
    }
                                                                                
    puts("shouldn'
t get here");
                                                                                
    exit(EXIT_SUCCESS);
}
使用wait and waitpid調(diào)用可以收集子進(jìn)程的退出狀態(tài)
Name
wait, waitpid - wait for process to change state
Synopsis
#include <sys/types.h>
#include <sys/wait.h>

pid_t wait(int *status);
pid_t waitpid(pid_t pid, int *status, int options);
int waitid(idtype_t idtype, id_t id "
, siginfo_t *" infop ", int " options );
Description
All of these system calls are used to wait for state changes in a child of the calling process, and obtain information about the child whose state has changed. A state change is considered to be: the child terminated; the child was stopped by a signal; or the child was resumed by a signal. In the case of a terminated child, performing a wait allows the system to release the resources associated with the child; if a wait is not performed, then terminated the child remains in a "
zombie" state (see NOTES below).

If a child has already changed state, then these calls return immediately. Otherwise they block until either a child changes state or a signal handler interrupts the call (assuming that system calls are not automatically restarted using the SA_RESTART flag of sigaction(2)). In the remainder of this page, a child whose state has changed and which has not yet been waited upon by one of these system calls is termed waitable.
wait() and waitpid()
The wait() system call suspends execution of the current process until one of its children terminates. The call wait(&status) is equivalent to:

waitpid(-1, &status, 0);

The waitpid() system call suspends execution of the current process until a child specified by pid argument has changed state. By default, waitpid() waits only for terminated children, but this behaviour is modifiable via the options argument, as described below.

The value of pid can be:

< -1
    meaning wait for any child process whose process group ID is equal to the absolute value of pid.
-1
    meaning wait for any child process.
0
    meaning wait for any child process whose process group ID is equal to that of the calling process.
> 0
    meaning wait for the child whose process ID is equal to the value of pid.

The value of options is an OR of zero or more of the following constants:

WNOHANG
    return immediately if no child has exited.
WUNTRACED
    also return if a child has stopped (but not traced via ptrace(2)). Status for traced children which have stopped is provided even if this option is not specified.
WCONTINUED
    (Since Linux 2.6.10) also return if a stopped child has been resumed by delivery of SIGCONT.
if you want to more information aboat it, you can reference http://linux.die.net.

example:
/*
 * waiter.c - Simple wait usage
 */
#include <unistd.h>
//#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
                                                                                
int main(void)
{
    pid_t child;
    int status;
                                                                                
    if((child = fork()) == -1) {
        perror("
fork");
        exit(EXIT_FAILURE);
    } else if(child == 0) {
        puts("
in child");
        printf("
\tchild pid = %d\n", getpid());
        printf("
\tchild ppid = %d\n", getppid());
        exit(EXIT_SUCCESS);
    } else {

        /* Wait for the child to exit */
        waitpid(child, &status, 0);
        printf("
in parent\n");
        printf("
\tparent pid = %d\n", getpid());
        printf("
\tparent ppid = %d\n", getppid());
        printf("
\tchild exited with %d\n", status);
    }
    exit(EXIT_SUCCESS);
}

abort()
#include <stdlib.h>
void abort(void)

kill()
#include <signal.h>
#include <sys/types.h>
int kill(pid_t pid, int sig)

example:
~/*
 * killer.c - Killing other processes
 */
#include <sys/types.h>
#include <sys/wait.h>//waitpid()
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>//signal
                                                                                
int main(void)
{
    pid_t child;
    int status, retval;
                                                                                
    if((child = fork()) < 0) {
        perror("
fork");
        exit(EXIT_FAILURE);
    }
    if(child == 0) {
        /* Sleep long enough to be killed */
        
         sleep(1000);
        exit(EXIT_SUCCESS);
    } else {
        /* Use WNOHANG so wait will return */
        if((waitpid(child, &status, WNOHANG)) == 0) {
            retval = kill(child, SIGKILL);
            if(retval) {
                /* Kill failed, so wait on child to exit */
                puts("
kill failed");
                perror("
kill");
                waitpid(child, &status, 0);
            } else
                printf("
%d killed\n", child);
        }
    }
    exit(EXIT_SUCCESS);
}
~
信 號(hào):
alarm(), pause(),kill(), sigfillset(),sigaction(),sigpending(),all the functions can find from the site http://linux.die.net

線程
_clone(), pthread_creat(), pthread_exit(),pthread_join(),pthread_atfork(),pthread_cancel(), pthread cleanup宏,pthread_equal()
線程互斥,pthread_mutex_init, pthread_mutex_lock
pthead 中的p display posix

from:
http://blog.chinaunix.net/u1/45689/showart_689217.html
posted on 2010-03-14 15:09 chatler 閱讀(525) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): Linux_Coding
<2010年3月>
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910

常用鏈接

留言簿(10)

隨筆分類(lèi)(307)

隨筆檔案(297)

algorithm

Books_Free_Online

C++

database

Linux

Linux shell

linux socket

misce

  • cloudward
  • 感覺(jué)這個(gè)博客還是不錯(cuò),雖然做的東西和我不大相關(guān),覺(jué)得看看還是有好處的

network

OSS

  • Google Android
  • Android is a software stack for mobile devices that includes an operating system, middleware and key applications. This early look at the Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.
  • os161 file list

overall

搜索

  •  

最新評(píng)論

閱讀排行榜

評(píng)論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美一区二区三区在线看| 国产精品毛片va一区二区三区| 久久一本综合频道| 欧美中文字幕| 欧美自拍偷拍| 久久久精品日韩| 美女精品在线观看| 亚洲国产另类 国产精品国产免费| 麻豆av一区二区三区| 欧美电影美腿模特1979在线看| 亚洲国产va精品久久久不卡综合| 亚洲精品欧美精品| 亚洲在线中文字幕| 久久免费视频网站| 欧美日韩一区综合| 国产亚洲制服色| 亚洲精品美女| 午夜精品久久99蜜桃的功能介绍| 久久久另类综合| 亚洲国产另类久久久精品极度| 妖精视频成人观看www| av成人福利| 国产一区二区三区观看| 久久亚洲欧美| 欧美日韩一区二区三区免费看| 国产精品少妇自拍| 影音国产精品| 亚洲男女自偷自拍| 欧美激情国产日韩| 亚洲欧美影音先锋| 欧美日韩精品中文字幕| 红桃视频欧美| 亚洲免费视频观看| 亚洲三级免费| 久久综合狠狠综合久久激情| 国产精品家庭影院| 99精品欧美一区二区蜜桃免费| 久久gogo国模裸体人体| 日韩一二三区视频| 欧美a级一区| 精品不卡视频| 久久国产精品毛片| 中文精品99久久国产香蕉| 免费欧美在线| 在线观看成人av电影| 久久久精品动漫| 亚洲欧美大片| 国产精品久久国产愉拍| 在线亚洲免费视频| 亚洲精品乱码久久久久| 嫩草影视亚洲| 亚洲精品少妇网址| 亚洲电影观看| 欧美成人精品三级在线观看| 亚洲福利视频三区| 免费成人在线观看视频| 久久精品一二三区| 好吊色欧美一区二区三区四区| 欧美在线地址| 欧美一级二级三级蜜桃| 国产亚洲欧美一级| 久久视频在线看| 久久本道综合色狠狠五月| 国产性天天综合网| 久久精品一区四区| 久久激情五月丁香伊人| 国外视频精品毛片| 久久久亚洲成人| 久久久国产精品一区二区中文 | 999在线观看精品免费不卡网站| 麻豆精品精华液| 亚洲黄色免费| 亚洲高清资源综合久久精品| 男人插女人欧美| 一本色道久久综合精品竹菊| 亚洲六月丁香色婷婷综合久久| 欧美日韩精品在线观看| 性做久久久久久| 欧美在线91| 午夜精品免费| 狂野欧美一区| 日韩亚洲一区二区| 亚洲伦理网站| 国产美女精品在线| 欧美福利影院| 欧美日韩国产探花| 久久精品国产亚洲精品| 久久手机精品视频| 亚洲视频999| 欧美在线免费一级片| 亚洲人成亚洲人成在线观看图片| 99re热这里只有精品免费视频| 国产精品视频九色porn| 蜜桃精品久久久久久久免费影院| 欧美日本亚洲| 久久麻豆一区二区| 欧美三级日本三级少妇99| 久久久久在线| 欧美视频免费在线| 免费在线欧美视频| 国产精品二区在线| 亚洲国产成人久久| 国产一区二区三区日韩欧美| 亚洲精品三级| 精品69视频一区二区三区| 99亚洲视频| 亚洲国产日韩欧美| 午夜精品福利在线| 一区二区三区高清在线| 久久一区亚洲| 久久激情视频| 欧美三级资源在线| 欧美激情中文不卡| 国产中文一区二区| 亚洲香蕉伊综合在人在线视看| 最新日韩欧美| 久久久欧美一区二区| 久久精品国产亚洲5555| 国产精品久久久久久一区二区三区| 免费成人小视频| 国产一区二区日韩| 亚洲一区综合| 亚洲一区二区三区四区视频| 欧美不卡高清| 欧美国产精品日韩| 尤物yw午夜国产精品视频| 性欧美精品高清| 欧美一级电影久久| 国产毛片一区二区| 亚洲欧美第一页| 校园春色国产精品| 国产精品美女一区二区| 亚洲少妇诱惑| 午夜一级久久| 国产视频一区二区在线观看| 午夜欧美不卡精品aaaaa| 亚洲欧美日韩中文在线制服| 国产精品高清在线| 亚洲一区日韩在线| 性欧美video另类hd性玩具| 欧美午夜精品久久久| 99精品欧美一区二区三区 | 香蕉国产精品偷在线观看不卡| 欧美三区在线观看| 亚洲大胆av| 亚洲欧美日韩另类| 亚洲在线视频| 国产精品任我爽爆在线播放| 在线视频日韩| 香港久久久电影| 国产婷婷色一区二区三区| 久久国产精彩视频| 免费在线观看一区二区| 亚洲国产精品第一区二区| 欧美69wwwcom| 99综合在线| 欧美综合国产精品久久丁香| 黄色精品网站| 欧美精品18videos性欧美| 亚洲天堂免费观看| 久久裸体艺术| 日韩香蕉视频| 国产欧美日韩在线视频| 免费一级欧美片在线观看| 亚洲精品久久在线| 欧美在线三区| 亚洲人成免费| 国产精品久久亚洲7777| 久久久久久欧美| 艳妇臀荡乳欲伦亚洲一区| 久久男人资源视频| 一本久久a久久精品亚洲| 国产人成精品一区二区三| 蜜桃伊人久久| 午夜免费久久久久| 日韩午夜在线| 久久婷婷久久| 亚洲在线国产日韩欧美| 亚洲国产三级网| 国产日韩精品一区观看| 欧美激情在线有限公司| 欧美一区二区三区免费视| 最新成人av在线| 久久久久久一区二区| 中文欧美日韩| 亚洲国产精品高清久久久| 国产精品自拍视频| 欧美日韩精品免费看| 久久久久久国产精品一区| 亚洲午夜精品久久久久久浪潮 | 欧美xx69| 久久激五月天综合精品| 亚洲网友自拍| 91久久亚洲| 狠狠色狠狠色综合系列| 国产精品久久久久久久久免费桃花 | 国产精品入口夜色视频大尺度| 免费成人黄色av| 久久gogo国模啪啪人体图| 亚洲一区二区三区在线看|