Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

linuxËøµÄÓ¦ÓÃ

ѧ¹ý²Ù×÷ϵͳµÄÈËÖªµÀÓÐÒ»¸ö·Ç³£ÖøÃûµÄÎÊÌ⣺¶ÁÕߣ­Ð´ÕßÎÊÌâ¡£¶ÁÕߣ­Ð´ÕßÎÊÌâÊÇָϵͳµ±ÖеĵÄ×ÊÔ´ÔÚijһʱ¼äÀï¿ÉÒÔͬʱÔÊÐí¶à¸ö½ø³Ì¶Á£¬µ«Ö»ÔÊÐíÒ»¸ö½ø³Ìд¡£Õâ¸ö½ø³Ìͬ²½ÎÊÌâµÄ½â·¨ÓÐÐí¶àÖÖ£¬ÔÚwindowϵͳÀïÓû¥³â±äÁ¿À´½øÐнø³ÌµÄͬ²½¡£ÔÚLinuxÀïÓÐÁíÒ»ÖÖ·½·¨£¬ÄǾÍÊÇÎļþËø£¬ÎļþËøÀïµÄÎļþ²»µ¥µ¥Ö»Ö¸Æ½Ê±Ëù˵µÄÎļþËüÓ¦°üº­¸ü¹ã·ºµÄº¬Òâ¡£¼´Ò²Ö¸ÏµÍ³ËùÓпÉÒÔ·ÃÎʵÄϵͳ×ÊÔ´¡£¿ÉÒÔ¸øÎļþ¼Ó¶ÁËø£¬Ò²¿ÉÒÔ¸øÎļþ¼ÓдËø£¬Ò»¸ö½ø³Ì¸øÒ»¸öÎļþ¼Ó¶ÁËøºóÆäËûµÄ½ø³ÌÒ²¿ÉÒÔ¸øÕâ¸öÎļþ¼Ó¶ÁËø£¬µ«ÊDz»¿ÉÒÔ¸øÕâ¸öÎļþ¼ÓдËø£¬Ö±µ½¸øÕâ¸öÎļþ¼Ó¶ÁËøµÄËùÓнø³Ì¶¼ReleaseÁËËü×Ô¼ºËù¼ÓµÄËøºó²Å¿ÉÒÔ¡£Èç¹ûÒ»¸ö½ø³Ì¸øÒ»¸öÎļþ¼ÓдËøºó£¬²»ÔÊÐíÆäËü½ø³Ì¶ÔÕâ¸öÎļþ¼ÓÈκεÄËø¡£ÏÂÃæÊÇËøµÄ¾ßÌåÓ¦Óᣣ¯
ÆäÖÐÓõ½Á˶à¸öϵͳº¯Êý£ºfcntl(),getpid(),getchar,open(),flock£¬read(),write()¡£
#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<string.h>
int lock_set(int fd,struct flock *lock)
{
    if(fcntl(fd,F_SETLK,lock)==0)
{
    if(lock->l_type==F_RDLCK)
        printf("set read lock,pid:%d\n",getpid());
    else if(lock->l_type==F_WRLCK)
        printf("set write lock,pid:%d\n",getpid());
    else if(lock->l_type=F_UNLCK)
        printf("release lock,pid:%d\n",getpid());
}
    else
    {
        printf("set lock operatiion fail\n");
        return -1;
}
    return 0;
}
int lock_test(int fd,struct flock *lock)
{
    if(fcntl(fd,F_GETLK,lock)==0)
{
    if(lock->l_type==F_UNLCK)
        printf("lock can be set by fd\n");
    else{
 if(lock->l_type=F_RDLCK)
        printf("can't set lock,read lock can be set by:%d\n",lock->l_pid);
    el


Ïà¹ØÎĵµ£º

Linux ÄÚºËÌåϵ¼ò½é¡¾×ª¡¿

1.Linux Äں˼ò½é ÏÖÔÚÈÃÎÒÃÇ´ÓÒ»¸ö±È½Ï¸ßµÄ¸ß¶ÈÀ´ÉóÊÓһϠGNU/Linux ²Ù×÷ϵͳµÄÌåϵ½á¹¹¡£Äú¿ÉÒÔ´ÓÁ½¸ö²ã´ÎÉÏÀ´¿¼ÂDzÙ×÷ϵͳ£¬Èçͼ 1 Ëùʾ¡£ ͼ 1. GNU/Linux ²Ù×÷ϵͳµÄ»ù±¾Ìåϵ½á¹¹ ×îÉÏÃæÊÇÓû§£¨»òÓ¦ÓóÌÐò£©¿Õ¼ä¡£ÕâÊÇÓû§Ó¦ÓóÌÐòÖ´Ðеĵط½¡£Óû§¿Õ¼äÖ®ÏÂÊÇÄں˿ռ䣬Linux ÄÚºËÕýÊÇλÓÚÕâÀï¡£ GNU C Lib ......

Linux Platform Device and Driver

´ÓLinux 2.6ÆðÒýÈëÁËÒ»Ì×еÄÇý¶¯¹ÜÀíºÍ×¢²á»úÖÆ:Platform_deviceºÍPlatform_driver¡£
LinuxÖд󲿷ֵÄÉ豸Çý¶¯£¬¶¼¿ÉÒÔʹÓÃÕâÌ×»úÖÆ, É豸ÓÃPlatform_device±íʾ£¬Çý¶¯ÓÃPlatform_driver½øÐÐ×¢²á¡£
 
Linux platform driver»úÖƺʹ«Í³µÄdevice driver »úÖÆ(ͨ¹ýdriver_registerº¯Êý½øÐÐ×¢²á)Ïà±È£¬Ò»¸öÊ®·ÖÃ÷ÏÔµÄÓ ......

linux Çý¶¯¼ÓÔزâÊÔÃüÁî

#insmod ./driver_xx.ko
´Ëʱ#cat /proc/devices ÄÜ¿´µ½ driver_xx É豸
#mknod /dev/mygpio c 230 0 (230ÊÇÖ÷É豸ºÅ£¬0ÊÇ×ÓÉ豸ºÅ£©
{ÕâÀï¿ÉÒÔÐÞ¸ÄÉ豸Ãû³Æ,µ«ÊÇÒªºÍ²âÊÔ³ÌÐòÖÐÒ»Ö fd_pio = open(“/dev/mygpio”, O_RDWR);
×îºÃºÍregister_chrdev(MY_PIO_MAJOR, "mygpio", &my_pio_fops)ÖеÄÒ»ÖÂ}
ʹ ......

linux¹ÒÔØÓÅÅ̼ÙËÀ

        ÓÉÓÚ fc3 ÄÚºËĬÈÏ fat32 Îļþϵͳ×Ö·û±àÂëÊÇ ascii£¬Èç¹ûÓÅÅ̵ÄÎļþÃû°üº¬ÖÐÎÄ£¬ÄÇôÔÚת»»Ê±»á³öÎÊÌ⣬ӦÓóÌÐò¾Í»áʧȥÏìÓ¦¡£¾ßÌåµÄ±íÏÖÓжàÖÖ£¬±ÈÈç×ÀÃæ¼ÙËÀ£¬¹Ø»úʱÌáʾÎÞ·¨Ð¶ÔØ·ÖÇøµÈµÈ
½â¾öµÄ°ì·¨ÊÇÔÚ¹ÒÔØʱ£¬¸ù¾ÝÓïÑÔ»·¾³ locale µÄÖµ£¬Ê¹ÓùÒÔزÎÊý¡£Èç¹ûÊÇ UTF- ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ