On 12-07-12 02:15 PM, vivek poddar wrote:
Hi,

I want to know that what is the function of the /dev directory in
linux and what is the meaning of /dev/pts and /dev/tty and what they
do.

AFAIK, historically, unix systems ran on mainframes and allowed multiple users to login simultaneously through teletype terminals (what I believe we call as dumb-terminals these days). All this was before my time so don't quote me on it. The teletype terminology is followed since then on unix/linux systems.

You may very (Very VERY) loosely associate a tty with a monitor but the correct way to think about it is thus (again my interpretation). Each *nix system assumes you have several dumb-terminals (ttys) connected to them (tty1-tty50). These are the multiple login prompts you can access by pressing the Ctrl+Alt+F? key combinations. Since within each session, a user may launch multiple terminal prompts, these terminal prompts are associated with pseudo-terminals (pts). You can try this out by starting a prompt (or logging in to a tty) and typing the command "tty".

If I remember correctly, linux has 4 kind of devices (or rather, device interfaces). You have character type devices (ttys), block devices (diskdrives,ramdisks), and two more that I can't remember (was fifos another one?). The /dev directory provides access to all these devices through the open/read/write etc system calls (sockets are also treated as character streams, I believe). In fact, if you go to /dev and run
 $ ls -l
you'll see entries that indicate the type of device (the first character), e.g.,

crw-rw-rw-  1 root tty       5,   0 2012-07-13 13:31 tty
brw-rw----  1 root disk      1,   0 2012-07-12 12:43 ram0
brw-rw----  1 root disk      8,   0 2012-07-12 12:43 sda

If you want to see what's written on your harddrive block by block (or character by character), you can open /dev/sda in a C (or perl or even Java) program and start reading it. Of course, you will need root permission and you run the risk of causing irreparable damage do your data.

Until several years back, /dev was populated with pointers to all conceivable devices that can be created (or else, these were statically created [2]). That's why, the "mount -o bind /dev /path/to/chroot/dev" trick also works [3]. With udev, I noticed that /dev was not populated with all device pointers but a plug-and-play feature was implemented [1].

Some references you may want to look at are:
 The Linux Kernel Module Programming Guide (LKMPG) [4]
    the chapter on Character devices [5]

In particular, I found what I was looking for. See section 3.1.6 of LKMPG [6]. This explains what /dev is for.


My 2 cents..
Sharad


[1] http://en.wikipedia.org/wiki/Udev
[2] http://www.tldp.org/LDP/lfs/LFS-BOOK-6.1.1-HTML/chapter06/devices.html
[3] http://fermilinux.fnal.gov/documentation/tips/mount-bind-chroot/
[4] http://www.tldp.org/LDP/lkmpg/2.6/html/index.html
[5] http://www.tldp.org/LDP/lkmpg/2.6/html/x569.html
[6] http://www.tldp.org/LDP/lkmpg/2.6/html/x427.html

--
Mailing list guidelines and other related articles: http://lug-iitd.org/Footer

Reply via email to