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

posts - 297,  comments - 15,  trackbacks - 0
process進程 and thread
獲取當前進程getpid(),父進程getppid(),當前用戶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;
}

獲取登錄用戶的個人信息,如用戶名,當前目錄,用戶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()
如果沒有找到/bin/sh則返回127,成功返回0,出錯返回-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調用創建一個新進程
#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.執行成功,就向父進程返回子進程的PID,并向子進程返回0,只調用一次fork,它會返回兩次

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()函數族
exec用被執行的程序完全替換了調用進程的映像。exec啟動一個新程序,替換原有的進程
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[]);
以上的函數都必須以NULL結束

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調用可以收集子進程的退出狀態
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);
}
~
信 號:
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) 評論(0)  編輯 收藏 引用 所屬分類: Linux_Coding
<2009年11月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

常用鏈接

留言簿(10)

隨筆分類(307)

隨筆檔案(297)

algorithm

Books_Free_Online

C++

database

Linux

Linux shell

linux socket

misce

  • cloudward
  • 感覺這個博客還是不錯,雖然做的東西和我不大相關,覺得看看還是有好處的

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

搜索

  •  

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            久久国产主播| 国产精品多人| 一区二区成人精品 | 国产亚洲一区二区三区| 欧美四级在线| 国产精品久久久久久久久久三级 | 欧美一区二区三区在| 一本一本久久a久久精品综合妖精| 亚洲精品影视| 亚洲在线视频网站| 久久久久久久久久久久久女国产乱| 久久伊人精品天天| 欧美日韩中文在线观看| 国产麻豆日韩欧美久久| 精品91免费| 一区二区三区四区在线| 久久精品国产第一区二区三区| 老鸭窝91久久精品色噜噜导演| 欧美二区在线播放| 亚洲天堂久久| 免费观看成人www动漫视频| 欧美性感一类影片在线播放 | 含羞草久久爱69一区| 99在线热播精品免费| 久久精品在线观看| 最新国产精品拍自在线播放| 日韩午夜在线播放| 久久精品91久久久久久再现| 欧美日韩亚洲激情| 在线日韩欧美视频| 欧美一区二视频| 亚洲精品四区| 久久综合久久美利坚合众国| 国产精品美女xx| 日韩视频欧美视频| 欧美成人一区在线| 亚洲欧美中文另类| 欧美午夜在线一二页| 亚洲精品免费电影| 欧美暴力喷水在线| 香港久久久电影| 国产精品亚洲片夜色在线| 日韩亚洲在线观看| 美女成人午夜| 久久精品九九| 黑人巨大精品欧美一区二区 | 欧美四级在线观看| 一区二区欧美激情| 亚洲国产精品久久久久久女王| 欧美中文字幕在线| 国产亚洲欧美另类中文| 欧美自拍偷拍| 欧美亚洲一区| 国产亚洲毛片| 久久久久国内| 久久女同精品一区二区| 尤物九九久久国产精品的分类| 久久久久88色偷偷免费| 香蕉久久国产| 国产精品成人播放| 亚洲自拍另类| 国产女精品视频网站免费| 亚洲视频在线一区| 99精品国产在热久久| 欧美色另类天堂2015| 亚洲视频大全| 亚洲一区二区免费在线| 国产精品伊人日日| 久久精品毛片| 久久亚洲不卡| 亚洲免费观看在线观看| 亚洲精品午夜精品| 国产精品久久久久久妇女6080| 亚洲欧美一区二区原创| 亚洲欧美激情精品一区二区| 国产综合视频| 欧美黄色网络| 欧美日韩直播| 久久久777| 欧美顶级大胆免费视频| 亚洲一区在线观看视频| 欧美一区二区| 亚洲精品国产精品国自产观看| 亚洲美女在线观看| 国产欧美在线| 亚洲国产精品国自产拍av秋霞| 欧美日本亚洲视频| 久久精品一区四区| 欧美好骚综合网| 欧美一区二区国产| 欧美不卡三区| 欧美在线视频一区| 欧美高清视频www夜色资源网| 亚洲影视综合| 嫩草影视亚洲| 欧美伊久线香蕉线新在线| 欧美1区2区视频| 欧美在线观看视频在线| 欧美韩日高清| 久久婷婷av| 国产精品捆绑调教| 欧美国产综合| 国产综合婷婷| 亚洲一区二区毛片| 亚洲美女在线观看| 久久精品一区二区三区不卡牛牛 | 亚洲乱码国产乱码精品精天堂| 亚洲无限av看| 日韩午夜在线电影| 久久久爽爽爽美女图片| 香港久久久电影| 欧美精品一区二区三区高清aⅴ| 久久精品中文| 国产精品专区一| 日韩午夜在线视频| 91久久精品一区二区别| 久久国产欧美日韩精品| 欧美诱惑福利视频| 国产精品国产三级国产专播精品人| 免费毛片一区二区三区久久久| 99视频精品全部免费在线| 久久综合久色欧美综合狠狠| 午夜在线a亚洲v天堂网2018| 欧美劲爆第一页| 欧美激情一区二区三区蜜桃视频| 国产午夜精品一区二区三区欧美| 正在播放亚洲一区| 亚洲图中文字幕| 欧美日韩在线播放三区| 亚洲靠逼com| 一区二区三区回区在观看免费视频| 狂野欧美激情性xxxx欧美| 美女在线一区二区| 在线成人激情黄色| 久久综合九色综合久99| 免费永久网站黄欧美| 亚洲高清电影| 欧美成人精品高清在线播放| 欧美激情精品久久久久久| 91久久精品美女| 欧美精品v日韩精品v韩国精品v| 欧美jizz19hd性欧美| 亚洲国产精品一区二区www| 开心色5月久久精品| 欧美激情一区三区| 日韩一区二区精品在线观看| 欧美日本不卡| 一区二区三区精品视频在线观看| 亚洲永久在线| 国产亚洲综合性久久久影院| 久久久精品五月天| 欧美大片免费观看| 99精品黄色片免费大全| 国产精品jizz在线观看美国| 亚洲欧美资源在线| 乱中年女人伦av一区二区| 亚洲精品国产日韩| 国产精品久久久久久久久免费桃花 | 鲁大师成人一区二区三区| 欧美激情在线有限公司| 一二三区精品福利视频| 国产精品乱码人人做人人爱| 欧美一区午夜精品| 亚洲高清资源| 午夜视频一区二区| 亚洲国产精品成人精品| 欧美日韩国语| 欧美伊久线香蕉线新在线| 亚洲国产三级网| 欧美一区二区三区四区在线观看| 在线精品视频一区二区三四| 欧美日韩午夜激情| 久久精品国产亚洲精品| 亚洲精选中文字幕| 狼人社综合社区| 亚洲影院色无极综合| 亚洲电影自拍| 国产色产综合色产在线视频| 欧美国产综合视频| 久久黄金**| 制服丝袜亚洲播放| 亚洲第一视频| 久久久噜噜噜久久中文字免| 一区二区冒白浆视频| 在线成人h网| 国产欧美69| 亚洲黄一区二区三区| 国产欧美日韩在线播放| 另类专区欧美制服同性| 亚洲一区国产精品| 亚洲国产精品久久久久秋霞蜜臀| 欧美中文在线观看国产| 在线视频一区二区| 亚洲黄页视频免费观看| 国产午夜精品全部视频播放| 欧美日韩一区二区三区免费看| 理论片一区二区在线| 久久精品国产精品| 亚洲影院免费观看| 在线亚洲自拍|