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

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
<2025年9月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用鏈接

留言簿(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>
            免费在线看成人av| 亚洲理论在线| 欧美电影在线观看| 欧美福利电影网| 麻豆成人综合网| 欧美大片一区二区| 欧美日本高清| 欧美午夜大胆人体| 国产精品一区二区a| 国产综合18久久久久久| 亚洲大片一区二区三区| 亚洲国产日韩在线一区模特| 亚洲精品少妇30p| 亚洲一级电影| 午夜精品福利视频| 久久久久久久精| 欧美激情1区2区3区| 久久手机精品视频| 欧美日韩福利在线观看| 国产日韩亚洲欧美精品| 亚洲人成网站在线观看播放| 亚洲欧美国产va在线影院| 久久中文在线| 久久国产精彩视频| 亚洲先锋成人| 91久久精品国产| 午夜精品成人在线视频| 久久久激情视频| 91久久视频| 亚洲一区二区在线免费观看| 国产免费亚洲高清| 亚洲欧洲日本专区| 久久久99国产精品免费| 亚洲免费播放| 久久漫画官网| 欧美大片免费久久精品三p | 欧美在线播放| 免费国产一区二区| 一区二区三区欧美亚洲| 欧美一区观看| 国产精品毛片大码女人| 亚洲精品国产精品国自产观看| 久久久久久久一区二区三区| 99国产一区| 欧美二区乱c少妇| 亚洲第一精品夜夜躁人人躁| 久久久一二三| 亚洲中午字幕| 国产精品欧美久久久久无广告| 亚洲精品自在在线观看| 久久免费偷拍视频| 欧美一级在线播放| 国产日韩欧美成人| 一区二区三区欧美日韩| 欧美激情一级片一区二区| 激情国产一区二区| 久久精品综合| 久久激情网站| 国产专区一区| 免费观看一级特黄欧美大片| 亚洲综合精品四区| 国产农村妇女精品一二区| 亚洲天堂黄色| 在线视频欧美一区| 国产精品日韩专区| 国产精品99久久不卡二区| 亚洲激情成人网| 欧美日韩成人在线观看| 亚洲午夜影视影院在线观看| 亚洲天堂黄色| 国产亚洲一区二区三区| 麻豆精品网站| 欧美精选一区| 亚洲欧美三级在线| 欧美亚洲系列| 在线成人免费观看| 亚洲成人在线视频网站| 欧美激情一区二区三区四区| 亚洲视频电影在线| 欧美一区二区视频在线观看| 激情文学一区| 欧美激情按摩在线| 欧美日韩亚洲国产精品| 性欧美1819性猛交| 午夜视频一区在线观看| 国产一区欧美| 亚洲国产免费| 蜜桃av综合| 嫩模写真一区二区三区三州| 一本色道**综合亚洲精品蜜桃冫 | 亚洲午夜一区| 影音先锋久久久| 亚洲精品视频二区| 国产精品人人爽人人做我的可爱| 欧美日韩小视频| 久久久亚洲精品一区二区三区| 亚洲欧美久久久| 日韩午夜剧场| 久久经典综合| 亚洲精品久久久久久久久久久| 亚洲一区在线直播| 亚洲区欧美区| 羞羞视频在线观看欧美| 一区二区不卡在线视频 午夜欧美不卡在 | 91久久国产综合久久蜜月精品 | 欧美一级在线播放| 久久国内精品视频| 中文日韩在线视频| 久久久久中文| 午夜精品一区二区三区在线视 | 亚洲精品午夜| 性欧美超级视频| 日韩视频在线一区| 亚洲欧美综合国产精品一区| 亚洲欧洲中文日韩久久av乱码| 欧美一区二区免费观在线| 国产精品99久久久久久久女警| 久久久精品国产免费观看同学| 亚洲激情电影中文字幕| 亚洲一级黄色av| 99视频精品免费观看| 久久人人97超碰国产公开结果| 欧美一区二区精品久久911| 欧美精品一区二区蜜臀亚洲| 久热精品视频| 伊人久久成人| 欧美伊人精品成人久久综合97 | 欧美freesex交免费视频| 国产精品中文在线| 在线一区二区三区做爰视频网站| 亚洲精品一区二区三区婷婷月 | 久久成人免费| 亚洲一二三区在线| 欧美日韩国产综合久久| 欧美高清hd18日本| 精品成人乱色一区二区| 香蕉视频成人在线观看 | 亚洲精品一区二区三区福利| 在线色欧美三级视频| 久久久久99| 免费观看在线综合色| 激情综合视频| 久久人人看视频| 欧美国产日产韩国视频| 亚洲第一精品夜夜躁人人爽| 久久九九99| 久久久精品国产免大香伊| 国外成人在线| 性18欧美另类| 久久天天躁夜夜躁狠狠躁2022| 国内精品视频一区| 久久久久综合网| 亚洲观看高清完整版在线观看| 亚洲国产成人久久综合| 久久天天狠狠| 亚洲人成人一区二区三区| 日韩亚洲欧美在线观看| 欧美日韩亚洲91| 一区二区三区欧美亚洲| 久久久久久久久久久久久久一区| 国产一区二区毛片| 老司机凹凸av亚洲导航| 欧美激情片在线观看| 日韩午夜在线电影| 欧美视频在线一区| 亚洲欧美另类久久久精品2019| 久久美女性网| 亚洲毛片在线观看| 国产精品成人一区二区三区夜夜夜| 亚洲网在线观看| 欧美国产精品久久| 一区二区三区四区五区精品视频 | 狂野欧美一区| 日韩视频在线一区| 欧美一区二区三区啪啪| 国产在线欧美| 欧美精品一区二区三区在线播放 | 亚洲精品五月天| 国产伦精品一区| 久久野战av| 日韩一区二区免费看| 欧美一区二区精品久久911| 激情综合色丁香一区二区| 欧美国产视频在线观看| 欧美国产日韩视频| 午夜一区在线| 亚洲福利小视频| 欧美一区二区三区免费视| 亚洲欧洲日产国产综合网| 国产精品午夜春色av| 蜜桃av综合| 欧美一区二区| 99这里只有精品| 欧美电影打屁股sp| 老司机67194精品线观看| 亚洲视频导航| 亚洲色在线视频| 亚洲日本中文字幕| 影音先锋日韩资源| 国产欧美亚洲视频|