Android system development (6)-underlying Linux Input and Output

Source: Internet
Author: User

Android system development (6)-underlying Linux Input and Output
1. The operating system architecture computer is composed of a pile of hardware. The operating system is used to effectively control these hardware resources. In addition to effectively controlling the allocation of these hardware resources and providing the functions required for computer operation, the operating system provides an environment where programmers can easily develop software, the Operating System also provides a whole set of system call interfaces.
As shown in, the most intermediate part is hardware. The operating system is composed of the kernel and the system call interface. The kernel directly operates the hardware, the kernel provides control over these hardware resources and process management. The system call interface provides a unified call interface for developers to call. The top layer is the application. You can call the system interface in the application to perform hardware operations. Ii. Linux I/O system
For example, in the Linux I/O system structure, the kernel layer has a virtual file system, which is an api encapsulated by a standard c class library, therefore, to operate the file system, you only need to call the api here.
Iii. Operation Process of I/O 1. Open the file. An application requests the kernel to open the corresponding file and declares that it wants to access an I/O device. The kernel returns a non-negative integer, descriptZ delimiter? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> latency + tsGjurTTzsS8/r + latency/latency + qzsS8/ra808nOxLz + w + weight/sPoyva3 + 8rH0ru49rfHuLrV + examples + samples/samples + samples/sPoyva3 + 2ZkserKtrjDzsS8/samples/sPoyva3 + samples/samples + LXsCwgy/samples + 7 urTmPHA + samples/ihornixcy78sbky/samples + samples/s + 1zbO2vL /keys + ztLDx9PDbHPD/keys + keys/bBy9K7uPaz6c/zsuOjrMq5tcPOxLz + keys/s + 1zbO/keys = "http://www.2cto.com/uploadfile/Collfiles/20140825/2014082508530025.png" alt = "\"/>

4. Linux underlying Input and Output we can go to GNU to download the libc source code and help documentation (source code: http://ftp.gnu.org/gnu/glibc/) open and close the file stream
#include 
 
  #include 
  
   #include 
   
    #include 
    
     #include 
     
      int main(int argc, char *argv[]){        //open file        if(argc<2){                printf("please input filename\n");                exit(1);        }else{                int fd;                umask(0000);                fd = open(argv[1], O_RDWR|O_CREAT, 0666);                if(fd < -1){                        printf("error\n");                        exit(1);                }else{                        printf("success=%d\n", fd);                        close(fd);                        printf("closed\n");                }        }        return 0;}
     
    
   
  
 
Read a file (the process of writing a file is similar to that of reading a file)
#include 
 
  #include 
  
   #include 
   
    #include 
    
     #include 
     
      #include 
      
       int main(int argc, char *argv[]){ //open file if(argc<2){ printf("please input filename\n"); exit(1); }else{ int fd; umask(0000); fd = open(argv[1], O_RDWR|O_CREAT, 0666); if(fd < -1){ printf("error\n"); exit(1); }else{ printf("success=%d\n", fd); char buf[1024]; memset(buf, 0, 1024); int returnum = read(fd, buf, 1024); if(returnum != -1){ printf("buf=%s\n", buf); }else{ printf("read error\n"); exit(1); } close(fd); printf("closed\n"); } } return 0;}
      
     
    
   
  
 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.