Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB
ÈÈÃűêÇ©£º c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 ×îÐÂÎÄÕ : linux

Linux Assembly "Hello World" Tutorial, CS 200

 
by Bjorn Chambless
Introduction
The following is designed familiarize the reader with programming in x86 (AT&T
style, that produced by gcc) assembly under Linux and how to interface assembly
and higher-level language code (i.e. C). The tutorial will also briefly cover
debugging your assembly using GDB.
This tutorial requires the following:
an i386 family PC running Linux
GCC, the GNU C-compiler
GDB, the GNU debugger command line debugger
The tutorial was developed on and tested with GCC version 2.95.4 and GDB 19990928 under Linux kernel 2.4.9
I highly recommend working through this tutorial with
"as"
and "gdb"

documentation close at hand.
Source Code
The process begins with a source code program. For example, hello.c
/* hello.c */
#include
main()
{
printf("hello\n").
}
which, when compiled and executed, prints a message
linuxbox> gcc -o hello hello.c
linuxbox> ./hello
hello
The actual compilation proce ......

Éú²úÕß Ïû·ÑÕßÎÊÌâʵÏÖ (linuxÏÂCÓïÑÔ)

²Ù×÷ϵͳµÄÒ»¸ö¾­µäÎÊÌâÊÇ"Éú²úÕß-Ïû·ÑÕß"ÎÊÌâ, ÕâÉæ¼°Í¬²½ÐźÅÁ¿ºÍ»¥³âÐźÅÁ¿µÄÓ¦ÓÃ, ÔÚÕâÀï,ÎÒÓÃÏ̵߳Äͬ²½ºÍ»¥³âÀ´ÊµÏÖ.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <semaphore.h>
#define N 2   // Ïû·ÑÕß»òÕßÉú²úÕßµÄÊýÄ¿
#define M 10 // »º³åÊýÄ¿
int in = 0;   // Éú²úÕß·ÅÖòúÆ·µÄλÖÃ
int out = 0; // Ïû·ÑÕßÈ¡²úÆ·µÄλÖÃ
int buff[M] = {0}; // »º³å³õʼ»¯Îª0£¬ ¿ªÊ¼Ê±Ã»ÓвúÆ·
sem_t empty_sem; // ͬ²½ÐźÅÁ¿£¬ µ±ÂúÁËʱ×èÖ¹Éú²úÕ߷ŲúÆ·
sem_t full_sem;   // ͬ²½ÐźÅÁ¿£¬ µ±Ã»²úƷʱ×èÖ¹Ïû·ÑÕßÏû·Ñ
pthread_mutex_t mutex; // »¥³âÐźÅÁ¿£¬ Ò»´ÎÖ»ÓÐÒ»¸öÏ̷߳ÃÎÊ»º³å
int product_id = 0;   //Éú²úÕßid
int prochase_id = 0; //Ïû·ÑÕßid
/* ´òÓ¡»º³åÇé¿ö */
void print()
{
int i;
for(i = 0; i < M; i++)
   printf("%d ", buff[i]);
printf("\n");
}
/* Éú²úÕß·½·¨ */

void *product()
{
int id = ++product_id;
while(1)
{
   // Ó ......

Éú²úÕß Ïû·ÑÕßÎÊÌâʵÏÖ (linuxÏÂCÓïÑÔ)

²Ù×÷ϵͳµÄÒ»¸ö¾­µäÎÊÌâÊÇ"Éú²úÕß-Ïû·ÑÕß"ÎÊÌâ, ÕâÉæ¼°Í¬²½ÐźÅÁ¿ºÍ»¥³âÐźÅÁ¿µÄÓ¦ÓÃ, ÔÚÕâÀï,ÎÒÓÃÏ̵߳Äͬ²½ºÍ»¥³âÀ´ÊµÏÖ.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <semaphore.h>
#define N 2   // Ïû·ÑÕß»òÕßÉú²úÕßµÄÊýÄ¿
#define M 10 // »º³åÊýÄ¿
int in = 0;   // Éú²úÕß·ÅÖòúÆ·µÄλÖÃ
int out = 0; // Ïû·ÑÕßÈ¡²úÆ·µÄλÖÃ
int buff[M] = {0}; // »º³å³õʼ»¯Îª0£¬ ¿ªÊ¼Ê±Ã»ÓвúÆ·
sem_t empty_sem; // ͬ²½ÐźÅÁ¿£¬ µ±ÂúÁËʱ×èÖ¹Éú²úÕ߷ŲúÆ·
sem_t full_sem;   // ͬ²½ÐźÅÁ¿£¬ µ±Ã»²úƷʱ×èÖ¹Ïû·ÑÕßÏû·Ñ
pthread_mutex_t mutex; // »¥³âÐźÅÁ¿£¬ Ò»´ÎÖ»ÓÐÒ»¸öÏ̷߳ÃÎÊ»º³å
int product_id = 0;   //Éú²úÕßid
int prochase_id = 0; //Ïû·ÑÕßid
/* ´òÓ¡»º³åÇé¿ö */
void print()
{
int i;
for(i = 0; i < M; i++)
   printf("%d ", buff[i]);
printf("\n");
}
/* Éú²úÕß·½·¨ */

void *product()
{
int id = ++product_id;
while(1)
{
   // Ó ......

LinuxÏÂcronµÄʹÓÃ

ronÊÇÒ»¸ölinuxÏµĶ¨Ê±Ö´Ðй¤¾ß£¬¿ÉÒÔÔÚÎÞÐèÈ˹¤¸ÉÔ¤µÄÇé¿öÏÂÔËÐÐ×÷Òµ¡£ÓÉÓÚCron ÊÇLinuxµÄÄÚÖ÷þÎñ£¬µ«Ëü²»×Ô¶¯ÆðÀ´£¬¿ÉÒÔÓÃÒÔÏµķ½·¨Æô¶¯¡¢¹Ø±ÕÕâ¸ö·þÎñ:
¡¡¡¡/sbin/service crond start //Æô¶¯·þÎñ
¡¡¡¡/sbin/service crond stop //¹Ø±Õ·þÎñ
¡¡¡¡/sbin/service crond restart //ÖØÆô·þÎñ
¡¡¡¡/sbin/service crond reload //ÖØÐÂÔØÈëÅäÖÃ
¡¡¡¡ÄãÒ²¿ÉÒÔ½«Õâ¸ö·þÎñÔÚϵͳÆô¶¯µÄʱºò×Ô¶¯Æô¶¯:
¡¡¡¡ÔÚ/etc/rc.d/rc.localÕâ¸ö½Å±¾µÄĩβ¼ÓÉÏ:
¡¡¡¡/sbin/service crond start
¡¡¡¡ÏÖÔÚCronÕâ¸ö·þÎñÒѾ­ÔÚ½ø³ÌÀïÃæÁË£¬ÎÒÃǾͿÉÒÔÓÃÕâ¸ö·þÎñÁË£¬Cron·þÎñÌṩÒÔϼ¸ÖÖ½Ó¿Ú¹©´ó¼ÒʹÓÃ:
¡¡¡¡1.Ö±½ÓÓÃcrontabÃüÁî±à¼­
¡¡¡¡cron·þÎñÌṩcrontabÃüÁîÀ´É趨cron·þÎñµÄ£¬ÒÔÏÂÊÇÕâ¸öÃüÁîµÄһЩ²ÎÊýÓë˵Ã÷:
¡¡¡¡crontab -u //É趨ij¸öÓû§µÄcron·þÎñ£¬Ò»°ãrootÓû§ÔÚÖ´ÐÐÕâ¸öÃüÁîµÄʱºòÐèÒª´Ë²ÎÊý
¡¡¡¡crontab -l //Áгöij¸öÓû§cron·þÎñµÄÏêϸÄÚÈÝ
¡¡¡¡crontab -r //ɾ³ýû¸öÓû§µÄcron·þÎñ
¡¡¡¡crontab -e //±à¼­Ä³¸öÓû§µÄcron·þÎñ
¡¡¡¡±ÈÈç˵root²é¿´×Ô¼ºµÄcronÉèÖÃ:crontab -u root -l
¡¡¡¡ÔÙÀýÈ磬rootÏëɾ³ýfredµÄcronÉèÖÃ:crontab -u fred -r
¡¡¡¡Ôڱ༭cron·þÎñʱ ......

linux Ðźűí

Ãû³Æ             Ä¬È϶¯×÷    ËµÃ÷
SIGHUP    ÖÕÖ¹½ø³Ì    ÖÕ¶ËÏß·¹Ò¶Ï
SIGINT   ÖÕÖ¹½ø³Ì    ÖжϽø³Ì
SIGQUIT  ½¨Á¢COREÎļþ   ÖÕÖ¹½ø³Ì£¬²¢ÇÒÉú³ÉcoreÎļþ
SIGILL   ½¨Á¢COREÎļþ   ·Ç·¨Ö¸Áî
SIGTRAP  ½¨Á¢COREÎļþ   ¸ú×Ù×ÔÏÝ
SIGBUS   ½¨Á¢COREÎļþ   ×ÜÏß´íÎó
SIGSEGV  ½¨Á¢COREÎļþ   ¶Î·Ç·¨´íÎó
SIGFPE   ½¨Á¢COREÎļþ   ¸¡µãÒì³£
SIGIOT   ½¨Á¢COREÎļþ   Ö´ÐÐI/O×ÔÏÝ
SIGKILL  ÖÕÖ¹½ø³Ì    É±ËÀ½ø³Ì
SIGPIPE  ÖÕÖ¹½ø³Ì    ÏòÒ»¸öûÓжÁ½ø³ÌµÄ¹ÜµÀдÊý¾Ý
SIGALARM  ÖÕÖ¹½ø³Ì    ¼ÆÊ±Æ÷µ½Ê±
SIGTERM  ÖÕÖ¹½ø³Ì    Èí¼þÖÕÖ¹ÐźÅ
SIGSTOP  Í£Ö¹½ø³Ì    ·ÇÖÕ¶ËÀ´µÄÍ£Ö¹ÐźÅ
SIGTSTP  Í£Ö¹½ø³Ì    ÖÕ¶ËÀ´µÄÍ£Ö¹ÐźÅ
SIGCONT  ºöÂÔÐźŠ  & ......

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. */
vo ......

LinuxµÄÆô¶¯²½Öè


Load Bios
Read MBR's config to find out the os
Load the kernel of the os
init Process starts
execute /etc/rc.d /sysinit
start other modules (etc/modules.conf)
execute the run level scripts
execute /etc/rc.d/rc.local
execute /bin/login
shell started
......
×ܼǼÊý:5772; ×ÜÒ³Êý:962; ÿҳ6 Ìõ; Ê×Ò³ ÉÏÒ»Ò³ [725] [726] [727] [728] 729 [730] [731] [732] [733] [734]  ÏÂÒ»Ò³ βҳ
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ