linuxÏß³Ì
ËùÓÐÏ̶߳¼ÓÐÒ»¸öÏ̺߳ţ¬Ò²¾ÍÊÇ
Thread ID
¡£ÆäÀàÐÍΪ
pthread_t
¡£Í¨¹ýµ÷ÓÃ
pthread_self()
º¯Êý¿ÉÒÔ»ñµÃ×ÔÉíµÄÏ̺߳š£
ÏÂÃæ˵һÏÂÈçºÎ´´½¨Ò»¸öÏ̡߳£
ͨ¹ý´´½¨Ị̈߳¬Ï߳̽«»áÖ´ÐÐÒ»¸öÏ̺߳¯Êý£¬¸ÃÏ̸߳ñʽ±ØÐë°´ÕÕÏÂÃæÀ´ÉùÃ÷£º
void * Thread_Function(void *)
´´½¨Ï̵߳ĺ¯ÊýÈçÏ£º
int pthread_create(pthread_t *restrict thread,
const pthread_attr_t *restrict attr,
void *(*start_routine)(void*), void *restrict arg);
ÏÂÃæ˵Ã÷һϸ÷¸ö²ÎÊýµÄº¬Ò壺
thread
£ºËù´´½¨µÄÏ̺߳š£
attr
£ºËù´´½¨µÄÏß³ÌÊôÐÔ£¬Õâ¸ö½«ÔÚºóÃæÏêϸ˵Ã÷¡£
start_routine
£º¼´½«ÔËÐеÄÏ̺߳¯Êý¡£
art
£º´«µÝ¸øÏ̺߳¯ÊýµÄ²ÎÊý¡£
ÏÂÃæÊÇÒ»¸ö¼òµ¥µÄ´´½¨Ïß³ÌÀý×Ó£º
#include <pthread.h>
#include <stdio.h>
/* Prints x’s to stderr. The parameter is unused. Does not return. */
void* print_xs (void* unused)
{
while (1)
fputc (‘x’, stderr);
return NULL;
}
/* The main program. */
int main ()
{
pthread_t thread_id;
/* Create a new thread. The new thread will run the print_xs
function. */
pthread_create (&thread_id, NULL, &print_xs, NULL);
/* Print o’s continuously to stderr. */
while (1)
fputc (‘o’, stderr);
return 0;
}
ÔÚ±àÒëµÄʱºòÐèҪעÒ⣬ÓÉÓÚÏ̴߳´½¨º¯ÊýÔÚ
libpthread.so
¿âÖУ¬ËùÒÔÔÚ±àÒëÃüÁîÖÐÐèÒª½«¸Ã¿âµ¼Èë¡£ÃüÁîÈçÏ£º
gcc –o createthread –lpthread createthread.c
Èç¹ûÏë´«µÝ²ÎÊý¸øÏ̺߳¯Êý£¬¿ÉÒÔͨ¹ýÆä²ÎÊý
arg
£¬ÆäÀàÐÍÊÇ
void *
¡£Èç¹ûÄãÐèÒª´«µÝ¶à¸ö²ÎÊýµÄ»°£¬¿ÉÒÔ¿¼Âǽ«ÕâЩ²ÎÊý×é³ÉÒ»¸ö½á¹¹ÌåÀ´´«µÝ¡£ÁíÍ⣬ÓÉÓÚÀàÐÍÊÇ
void *
£¬ËùÒÔÄãµÄ²ÎÊý²»¿ÉÒÔ±»ÌáÇ°Êͷŵô¡£
ÏÂÃæÒ»¸öÎÊÌâºÍÇ°Ãæ´´½¨½ø³ÌÀàËÆ£¬²»¹ý´øÀ´µÄÎÊÌâ»Ø±Ü½ø³ÌÒªÑÏÖصöࡣÈç¹ûÄãµÄÖ÷Ị̈߳¬Ò²¾ÍÊÇ
main
º¯ÊýÖ´ÐеÄÄǸöỊ̈߳¬ÔÚÄãÆäËûÏسÇÍƳö֮ǰ¾ÍÒѾÍ˳ö£¬ÄÇô´øÀ´µÄ
bug
Ôò²»¿É¹ÀÁ¿¡£Í¨¹ý
pthread_join
º¯Êý»áÈÃÖ÷Ïß³Ì×èÈû£¬Ö±µ½ËùÓÐÏß³
Ïà¹ØÎĵµ£º
¹À¼ÆÊDZ»¹¥»÷ÁË£¬¹ý¸ö¼ÙÆÚssh¾ÍÁ¬½Ó²»ÉÏÁË£¬Ô¶³ÌÁ¬½ÓÌáʾ network refused¡£Ö»ÄÜÅܵ½»ú·¿¿´¸ö¾¿¾¹£¬Ê×ÏÈÓôó¼ÒµÄÐ޸ķ½Ê½£º
LinuxÏÂSSHĬÈÏ22¶Ë¿ÚµÄÐ޸ķ½·¨ÈçÏÂ:
NO 1£º
01¼ÙÈçÒª¸ÄSSHµÄĬÈ϶˿ڣ¨22£©£¬ÄÇôÄãÖ»ÒªÐ޸ģº/etc/ssh/sshd_configÖÐPort 22£¬ÕâÀï°Ñ22¸Ä³É×Ô¼ºÒªÉèµÄ¶Ë¿Ú¾ÍÐÐÁË£¬²»¹ýǧÍò±ðÉèºÍÏÖÒÑÓеĶ ......
WgetÊÇÒ»¸öÊ®·Ö³£ÓÃÃüÁîÐÐÏÂÔع¤¾ß£¬¶àÊýLinux·¢Ðа汾¶¼Ä¬ÈÏ°üº¬Õâ¸ö¹¤¾ß¡£Èç¹ûûÓа²×°¿ÉÔÚ http: //www.gnu.org/software/wget/wget.html ÏÂÔØ×îа汾£¬²¢Ê¹ÓÃÈçÏÂÃüÁî±àÒë°²×°£º
# tar zxvf wget-1.9.1.tar.gz
# cd wget-1.9.1
# ./configure
# make
# make install
ËüµÄÓ÷¨ºÜ¼òµ¥.
1£©Ö§³Ö¶ÏµãÏ ......
ÍøÂçÎļþϵͳ£¨NFS£¬Network File System£©ÊÇÒ»ÖÖ½«Ô¶³ÌÖ÷»úÉϵķÖÇø£¨Ä¿Â¼£©¾ÍøÂç¹ÒÔص½±¾µØϵͳµÄÒ»ÖÖ»úÖÆ£¬Í¨¹ý¶ÔÍøÂçÎļþϵͳµÄÖ§³Ö£¬Óû§¿ÉÒÔÔÚ±¾µØϵͳÉÏÏñ²Ù×÷±¾µØ·ÖÇøÒ»ÑùÀ´¶ÔÔ¶³ÌÖ÷»úµÄ¹²Ïí·ÖÇø£¨Ä¿Â¼£©½øÐвÙ×÷¡£
ÔÚǶÈëʽLinux µÄ¿ª·¢¹ý³ÌÖУ¬¿ª·¢ÕßÐèÒªÔÚLinux ·þÎñÆ÷ÉϽøÐÐËùÓеÄÈí¼þ¿ª·¢£¬½»²æ±àÒëºó£¬Í¨Ó ......
²Ù×÷ϵͳµÄÒ»¸ö¾µäÎÊÌâÊÇ"Éú²úÕß-Ïû·ÑÕß"ÎÊÌâ, ÕâÉ漰ͬ²½ÐźÅÁ¿ºÍ»¥³âÐźÅÁ¿µÄÓ¦ÓÃ, ÔÚÕâÀï,ÎÒÓÃÏ̵߳Äͬ²½ºÍ»¥³âÀ´ÊµÏÖ.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <semaphore.h>
#define N 2 // Ïû·ÑÕß» ......
Ãû³Æ ĬÈ϶¯×÷ ˵Ã÷
SIGHUP ÖÕÖ¹½ø³Ì ÖÕ¶ËÏß·¹Ò¶Ï
SIGINT ÖÕÖ¹½ø³Ì ÖжϽø³Ì
SIGQUIT ½¨Á¢COREÎļþ ÖÕÖ¹½ø³Ì£¬²¢ÇÒÉú³ÉcoreÎļþ
SIGILL ......