Linux²Ù×÷ϵͳϵĶàÏ̱߳à³ÌÏêϸ½âÎö£¨3£©
3¡¢Ï̱߳êʶ
º¯ÊýÔÐÍ£º
#include <pthread.h>
pthread_t pthread_self(void);
pid_t getpid(void);
getpid()ÓÃÀ´È¡µÃÄ¿Ç°½ø³ÌµÄ½ø³Ìʶ±ðÂë,º¯Êý˵Ã÷
Àý³Ì8
³ÌÐòÄ¿µÄ£ºÊµÏÖÔÚн¨Á¢µÄÏß³ÌÖдòÓ¡¸ÃÏ̵߳ÄidºÍ½ø³Ìid
³ÌÐòÃû³Æ£ºpthread_id.c
/********************************************************************************************
** Name:pthread_id.c
** Used to study the multithread programming in Linux OS.
** Showing how to get the thread's tid and the process's pid.
** Author:zeickey
** Date:2006/9/16
** Copyright (c) 2006,All Rights Reserved!
*********************************************************************************************/
#include <stdio.h>
#include <pthread.h>
#include <unistd.h> /*getpid()*/
void *create(void *arg)
{
printf("New thread .... \n");
printf("This thread's id is %u \n", (unsigned int)pthread_self());
printf("The process pid is %d \n",getpid());
return (void *)0;
}
int main(int argc,char *argv[])
{
pthread_t tid;
int error;
printf("Main thread is starting ... \n");
error = pthread_create(&tid, NULL, create, NULL);
if(error)
{
printf("thread is not created ... \n");
return -1;
}
printf("The main process's pid is %d \n",getpid());
sleep(1);
return 0;
}
±àÒë·½·¨£º
gcc -Wall -lpthread pthread_id.c
Ö´Ðнá¹û£º
Ma
Ïà¹ØÎĵµ£º
ÀïѧϰlinuxÎļþϵͳ¼¼ÇÉ£¬¹ÒÔØUÅÌÊÇ·ñÁ¬½ÓµÄ¼¼ÇÉ£¬ÎÄÖÐÒÔ°¸Àý½²½â¡£ÍûÄܸø´ó¼Ò´øÀ´Ð¡Ð¡µÄ°ïÖú¡£
LinuxÎļþϵͳÊÇÒì²½µÄ£¬Ò²¾ÍÊÇ˵дһ¸öÎļþ²»ÊÇÁ¢¿Ì±£´æµ½½éÖÊ£¨Ó²ÅÌ£¬UÅ̵ȣ©ÖУ¬¶øÊÇ´æµ½»º³åÇøÄÚ£¬µÈ»ýÀÛµ½Ò»¶¨³Ì¶ÈÔÙÒ»Æð±£´æµ½½éÖÊÖС£Èç¹ûûÓÐumount¾Í·Ç·¨°Î³ö UÅÌ£¬³ÌÐòÊDz»ÖªµÀµÄ£¬fopen,fwriteµÈº¯Êý¶¼ÒÀÈ»·µ»ØÕý ......
2009-10-27
1£¬ÖØÆô reboot
2009-10-28
1,Íü¼ÇÁËrootÓû§ÃÜÂëµÄ½â¾ö°ï
Æô¶¯ºó°´esc½øÈëÐÞ¸´Ä£Ê½£¬Ñ¡ÔñÐÞ¸´£¬²¢Ñ¡Ôñ×îºóÒ»¸ö¡£root£¬½øÈ¥ºó£¬¸ü¸ÄÃÜÂ룺passwd root
È»ºó¸ù¾ÝÌáʾÊäÈëÁ½´ÎÃÜÂë¾ÍÐÐÁË¡£
2009-10-29
1,ls
ls -a ²é¿´ËùÓÐÎļþ
ls -l ²é¿´ÏêϸµÄÊôÐÔ
&nbs ......
zieckey £¨zieckey£Àyahoo.com.cn£©
Ị̈߳¨thread£©¼¼ÊõÔçÔÚ60Äê´ú¾Í±»Ìá³ö£¬µ«ÕæÕýÓ¦ÓöàÏ̵߳½²Ù×÷ϵͳÖÐÈ¥£¬ÊÇÔÚ80Äê´úÖÐÆÚ£¬solarisÊÇÕâ·½ÃæµÄٮٮÕß¡£´«Í³µÄUnixÒ²Ö§³ÖÏ̵߳ĸÅÄµ«ÊÇÔÚÒ»¸ö½ø³Ì£¨process£©ÖÐÖ»ÔÊÐíÓÐÒ»¸öỊ̈߳¬ÕâÑù¶àÏ߳̾ÍÒâζ×Ŷà½ø³Ì¡£
ÏÖÔÚ£¬¶àÏ̼߳ ......
2¡¢Ï̵߳ÄÖÕÖ¹
Èç¹û½ø³ÌÖÐÈκÎÒ»¸öÏß³ÌÖе÷ÓÃexit£¬_Exit,»òÕßÊÇ_exit£¬ÄÇôÕû¸ö½ø³Ì¾Í»áÖÕÖ¹£¬
Óë´ËÀàËÆ£¬Èç¹ûÐźŵÄĬÈϵĶ¯×÷ÊÇÖÕÖ¹½ø³Ì£¬ÄÇô£¬°Ñ¸ÃÐźŷ¢Ë͵½Ï̻߳áÖÕÖ¹½ø³Ì¡£
Ï̵߳ÄÕý³£Í˳öµÄ·½Ê½£º
(1) Ïß³Ì ......