linuxÏÂʵÏÖ¶àÏß³Ìͬ²½£¨Ò»£©
²Î¿¼×ÊÁÏ£ºhttp://baike.baidu.com/view/400319.htm
¡¡LinuxϵͳϵĶàÏß³Ì×ñÑPOSIXÏ߳̽ӿڣ¬³ÆÎªpthread¡£±àдLinuxϵĶàÏ̳߳ÌÐò£¬ÐèҪʹÓÃÍ·Îļþpthread.h£¬Á¬½ÓʱÐèÒª ʹÓÿâlibpthread.a¡£Ë³±ã˵һÏ£¬LinuxÏÂpthreadµÄʵÏÖÊÇͨ¹ýϵͳµ÷ÓÃclone£¨£©À´ÊµÏֵġ£clone£¨£©ÊÇLinuxËùÌØ ÓеÄϵͳµ÷Óã¬ËüµÄʹÓ÷½Ê½ÀàËÆfork£¬¹ØÓÚclone£¨£©µÄÏêϸÇé¿ö£¬ÓÐÐËȤµÄ¶ÁÕß¿ÉÒÔÈ¥²é¿´ÓйØÎĵµËµÃ÷¡£ÏÂÃæÎÒÃÇչʾһ¸ö×î¼òµ¥µÄ¶àÏ̳߳ÌÐò example1.c
#include <stdio.h>
#include <pthread.h>
#include<sys/types.h>
void thread(void){
int i;
for(i=0;i<3;i++)
printf("This is a pthread.\n");
}
int main(void){
pthread_t id;
int i,ret;
ret = pthread_create(&id,NULL,(void*)thread,NULL);
if(ret!=0){
printf ("Create pthread error!\n");
// exit (1);
}
for(i=0;i<3;i++)
printf("This is the main process.\n");
pthread_join(id,NULL);
return (0);
}
ÎÒÃDZàÒë´Ë³ÌÐò£º
¡¡¡¡gcc example1.c -lpthread -o example1
ÎÒËùʹÓõÄÊÇÀÏʦ½ÌµÄ gcc example.c -g -o example -l phread
ÔËÐÐexample1£¬ÎÒÃǵõ½ÈçϽá¹û£º
This is the main process.
This is a pthread.
This is the main process.
This is the main process.
This is a pthread.
This is a pthread.
ÔÙ´ÎÔËÐУ¬ÎÒÃÇ¿ÉÄܵõ½ÈçϽá¹û£º
This is a pthread.
This is the main process.
This is a pthread.
This is the main process.
This is a pthread.
This is the main process.
¡¡¡¡Ç°ºóÁ½´Î½á¹û²»Ò»Ñù£¬ÕâÊÇÁ½¸öÏß³ÌÕù¶áCPU×ÊÔ´µÄ½á¹û¡£ÉÏÃæµÄʾÀýÖУ¬ÎÒÃÇʹÓõ½ÁËÁ½¸öº¯Êý£¬¡¡pthread_createºÍpthread_join£¬²¢ÉùÃ÷ÁËÒ»¸öpthread_tÐ͵ıäÁ¿¡£
¡¡¡¡pthread_tÔÚÍ·Îļþ/usr/include/bits/pthreadtypes.hÖж¨Ò壺
¡¡¡¡typedef unsigned long int pthread_t;
¡¡¡¡ËüÊÇÒ»¸öÏ̵߳ıêʶ·û¡£º¯Êýpthread_createÓÃÀ´´´½¨Ò»¸öỊ̈߳¬ËüµÄÔÐÍΪ£º
¡¡¡¡extern int pthread_create __P ((pthread_t *__thread, __const pthread_attr_t *__attr,
¡¡¡¡void *(*__start_routine) (void *), void *__arg));
¡¡¡¡µÚÒ»¸ö²ÎÊýΪָÏòÏ̱߳êʶ·ûµÄÖ¸Õ룬µÚ¶þ¸ö²ÎÊýÓÃÀ´ÉèÖÃÏß³ÌÊôÐÔ£¬µÚÈý¸ö²ÎÊýÊÇÏß³ÌÔËÐк¯ÊýµÄÆðʼµØÖ·
Ïà¹ØÎĵµ£º
Linuxϵͳµ÷ÓÃÁбí
±¾ÎÄÁгöÁ˴󲿷ֳ£¼ûµÄLinuxϵͳµ÷Ó㬲¢¸½ÓмòÒªÖÐÎÄ˵Ã÷¡£
ÒÔÏÂÊÇLinuxϵͳµ÷ÓõÄÒ»¸öÁÐ±í£¬°üº¬Á˴󲿷ֳ£ÓÃϵͳµ÷ÓúÍÓÉϵͳµ÷ÓÃÅÉÉú³öµÄµÄº¯Êý¡£Õâ¿ÉÄÜÊÇÄãÔÚ»¥ÁªÍøÉÏËùÄÜ¿´µ½µÄΨһһƪÖÐÎÄ×¢Ê͵ÄLinuxϵͳµ÷ÓÃÁÐ±í£¬¼´Ê¹ÊǼòµ¥µÄ×ÖĸÐòÓ¢ÎÄÁÐ±í£¬ÄÜ× ......
1¡¢ÓÃviÔÚ/etc/modprobe.d
Ŀ¼ÏÂн¨Îı¾Îļþbad_list
2¡¢ÔÚbad_list
ÀïÐÂÔöÒ»ÐÐalias net-pf-10 off
3¡¢ÖØÆðϵͳ£ºshutdown -r now
4¡¢½ûÓÃ֮ǰ»òÖ®ºó¿ÉÒÔÔÚ¿ØÖÆÌ¨ÓÃÈçÏÂÃüÁî¼ì²éÊDz»ÊÇÆðÓÃÁËIPv6:
ip a | grep inet6
¡¡ Êä³öÁËÄÚÈݱíÃ÷IPv6ÆðÓÃÁË£¬Ê²Ã´¶¼Ã»ÓбíÃ÷ÒѽûÓÃÁË
£»Ò ......
²Ù×÷ϵͳ£ºlinux£¨feroda4£©
tcl°æ±¾£ºtclsh8.4
expect£º5.43.0
sshµÇ¼½Å±¾
#!/usr/bin/tclsh8.4
package require Expect
set user "root"
set host "10.2.26.30"
spawn ssh $user@$host
expect {
-re "password: $"   ......
1. ϵͳÆô¶¯ºó,ÔÚ³öÏÖgrub»ÃæÊ±£¬ÓÃÉÏϼüÑ¡ÖÐÄãÆ½Ê±Æô¶¯linuxµÄÄÇÒ»ÏȻºó°´e¼ü
2. ÔÙ´ÎÓÃÉÏϼüÑ¡ÖÐÄãÆ½Ê±Æô¶¯linuxµÄÄÇÒ»Ïî(ÀàËÆÓÚkernel/boot mlinuz-2.4.18-14 ro root=LABEL=/)£¬È»ºó°´e¼ü
3. ÐÞ¸ÄÄãÏÖÔÚ¼ûµ½µÄÃüÁîÐУ¬¼ÓÈësingle£¬½á¹ûÈçÏ£º
kernel /boot mlinuz-2.4.18-14 single ro ......