Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. read/write function working in linux

read/write function working in linux

Scheduled Pinned Locked Moved C / C++ / MFC
linuxquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rupeshkp728
    wrote on last edited by
    #1

    I want to know how a read/write calls is accomplished in linux? I mean how a function say read() will read the data from a file. What all will be the steps from user mode read() function call to kernel mode? Will anybody explain the steps or let me know any site from where I can get this info?

    M L 2 Replies Last reply
    0
    • R rupeshkp728

      I want to know how a read/write calls is accomplished in linux? I mean how a function say read() will read the data from a file. What all will be the steps from user mode read() function call to kernel mode? Will anybody explain the steps or let me know any site from where I can get this info?

      M Offline
      M Offline
      Michel Godfroid
      wrote on last edited by
      #2
      1. I suggest you post in the linux forum. 2) Since this is all open source stuff, I suggest you have a look at the stdio library source code.
      R 1 Reply Last reply
      0
      • M Michel Godfroid
        1. I suggest you post in the linux forum. 2) Since this is all open source stuff, I suggest you have a look at the stdio library source code.
        R Offline
        R Offline
        rupeshkp728
        wrote on last edited by
        #3

        Thanks for the information.

        1 Reply Last reply
        0
        • R rupeshkp728

          I want to know how a read/write calls is accomplished in linux? I mean how a function say read() will read the data from a file. What all will be the steps from user mode read() function call to kernel mode? Will anybody explain the steps or let me know any site from where I can get this info?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Hi, All modern operating systems in protected mode [^]work nearly the same when executing privileged instructions. They all pass through a call gate[^] and allow the kernel to do the system call[^]. The modern system call instructions are SYSENTER/SYSEXIT. In the old days it was interrupt 0x2e in Windows and 0x80 in Linux. Here is an example of a Win32 function which is written with both 0x2e and SYSENTER syntax. http://www.codeproject.com/Messages/2468550/Re-Send-Key-Input.aspx[^] To answer your question I would summarize as follows: 1.) Glibc simply pushes your arguments onto the stack and invokes the sysenter instruction. (An older version of Linux will invoke interrupt 0x80) 2.) When the CPU sees the SYSENTER instruction it will JMP to the address listed in the registered SYSCALL table. It will execute the instructions there. (Here is where permissions and actual I/O is performed) Best Wishes, -David Delaune

          M R 2 Replies Last reply
          0
          • L Lost User

            Hi, All modern operating systems in protected mode [^]work nearly the same when executing privileged instructions. They all pass through a call gate[^] and allow the kernel to do the system call[^]. The modern system call instructions are SYSENTER/SYSEXIT. In the old days it was interrupt 0x2e in Windows and 0x80 in Linux. Here is an example of a Win32 function which is written with both 0x2e and SYSENTER syntax. http://www.codeproject.com/Messages/2468550/Re-Send-Key-Input.aspx[^] To answer your question I would summarize as follows: 1.) Glibc simply pushes your arguments onto the stack and invokes the sysenter instruction. (An older version of Linux will invoke interrupt 0x80) 2.) When the CPU sees the SYSENTER instruction it will JMP to the address listed in the registered SYSCALL table. It will execute the instructions there. (Here is where permissions and actual I/O is performed) Best Wishes, -David Delaune

            M Offline
            M Offline
            Moak
            wrote on last edited by
            #5

            :thumbsup: 5 from me, thanks!

            Chat in Europe :java: Now with 24% more Twitter

            1 Reply Last reply
            0
            • L Lost User

              Hi, All modern operating systems in protected mode [^]work nearly the same when executing privileged instructions. They all pass through a call gate[^] and allow the kernel to do the system call[^]. The modern system call instructions are SYSENTER/SYSEXIT. In the old days it was interrupt 0x2e in Windows and 0x80 in Linux. Here is an example of a Win32 function which is written with both 0x2e and SYSENTER syntax. http://www.codeproject.com/Messages/2468550/Re-Send-Key-Input.aspx[^] To answer your question I would summarize as follows: 1.) Glibc simply pushes your arguments onto the stack and invokes the sysenter instruction. (An older version of Linux will invoke interrupt 0x80) 2.) When the CPU sees the SYSENTER instruction it will JMP to the address listed in the registered SYSCALL table. It will execute the instructions there. (Here is where permissions and actual I/O is performed) Best Wishes, -David Delaune

              R Offline
              R Offline
              rupeshkp728
              wrote on last edited by
              #6

              Great reply. That clears it all. Also find a good description of query at: http://www.ibm.com/developerworks/linux/library/l-system-calls/ This reply is very much similar to the explaination for windows of read/write() as explained in the chapter IO systems of book Microsoft Windows Internals by Mark E. Russinovich and David A. Solomon

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups