tag:blogger.com,1999:blog-42242214850987445582024-03-06T13:06:48.460+05:30Embed Your CareerMr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.comBlogger73125tag:blogger.com,1999:blog-4224221485098744558.post-809021697651504012012-12-22T10:58:00.000+05:302012-12-22T10:58:32.633+05:30USB Enumeration<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: left;">
<span style="background-color: white; font-family: Arial, Helvetica, sans-serif;"><span style="line-height: 17.633333206176758px;">The process of identifying the device and setting a unique address is referred as </span><span class="docEmphasis" style="font-style: italic; line-height: 17.633333206176758px;"><b>bus enumeration</b></span><span style="line-height: 17.633333206176758px;"><b>.</b> The enumeration process is handled by the <b>system software</b> on the host and the <b>USB logical layer</b> on the device side. The enumeration process starts when a device is attached to the host and the device gets the power. The USB specification includes simple steps for enumeration.</span></span></div>
<div style="text-align: left;">
<span style="background-color: white; line-height: 17.633333206176758px;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div style="text-align: left;">
</div>
<ol style="text-align: left;">
<li><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">The USB device is attached to the host, which receives an event indicating a change in the pipe’s status. The USB device is in the powered state, and the port it is attached to is disabled.</span></li>
<li><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">The host queries about the change in the bus.</span></li>
<li><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">Once the host determines that a new device is attached, it waits for at least 100ms for the device to become stable after power, after which it enables and resets the port.</span></li>
<li><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">After a successful reset, the USB device is in a default state and can draw power to a range of 100 mA from VBUS pin.</span></li>
<li><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">Once the device is in a default state, the host assigns a unique address to the USB device, which moves the device to an address state.</span></li>
<li><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">The host starts communicating with the USB device in the default control pipe and reads the device descriptor.</span></li>
<li><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">Subsequently, the host reads the device configuration information</span></li>
<li><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">The host selects the configuration, which moves the device to a configured state and makes it ready for use.</span></li>
</ol>
</div>
Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com0tag:blogger.com,1999:blog-4224221485098744558.post-20276558754393726922012-12-19T12:32:00.000+05:302012-12-19T12:32:13.642+05:30Tasklet v/s Bottom Halves v/s Softirq <div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: left;">
<span style="background-color: white; font-family: Helvetica, Arial, sans-serif; line-height: 19px;">I spent good time reading the Linux Kernel things this morning. Here is what I found which explains the difference between bottom halves, tasklets and softirqs.</span></div>
<div style="text-align: left;">
<span style="background-color: white; font-family: Helvetica, Arial, sans-serif; line-height: 19px;"><br /></span></div>
<div style="text-align: left;">
</div>
<div style="border: 0px; margin-bottom: 15px; padding: 0px; vertical-align: baseline;">
<span style="background-color: white;"><span style="font-family: Helvetica, Arial, sans-serif;"><span style="line-height: 19px;">Softirqs and tasklets replaced bottom halves, because bottom halves were a large bottle neck on SMP systems. If a bottom half was running on one CPU no other bottom halves could run on any other CPU. It’s obvious how these would not scale. So here what I understand.</span></span></span></div>
<div style="border: 0px; font-family: Helvetica, Arial, sans-serif; line-height: 19px; margin-bottom: 15px; padding: 0px; vertical-align: baseline;">
<span style="background-color: white;">Softirqs and tasklets replaced bottom halves. The difference between softirqs and tasklets, is that a softirq is<b> guaranteed to run on the CPU it was scheduled on, where as tasklets don’t have that guarantee. Also the same tasklet can not run on two separate CPUS at the same time, where as a softirq can. Don’t confuse the tasklet restriction with that of the bottom halves. Two different tasklets can run on two different CPUs, just not the same one.</b></span></div>
<div style="border: 0px; margin-bottom: 15px; padding: 0px; vertical-align: baseline;">
<span style="background-color: white;"><span style="font-family: Helvetica, Arial, sans-serif;"><span style="line-height: 19px;"> I can't argue why we have tasklets (I’m trying to get rid of them ( if you have idea please share with me ) but I'll give the best example of why we have softirqs. That’s the networking code. Say you get a network packet. But to process that packet, it takes a lot of work. If you do that in the interrupt handler, no other interrupts can happen on that IRQ line. That would cause a large latency to incoming interrupts and perhaps you'll overflow the buffers and drop packets. So the interrupt handler only moves the data off to a network receive queue, and returns. But this packet still needs to be processed right away. Before anything else. So it goes off to a softirq for processing. Now you still allow for interrupts to come in. Perhaps the network interrupt comes in again on another CPU. The other CPU can start processing that packet with a softirq on that CPU, even before the first packet was done processing.</span></span></span></div>
<div style="border: 0px; margin-bottom: 15px; padding: 0px; vertical-align: baseline;">
<span style="background-color: white;"><span style="font-family: Helvetica, Arial, sans-serif;"><span style="line-height: 19px;">See how this can scale well? But the same tasklet can't run on two different CPUs, so it doesn't have this advantage. In fact if a tasklet is scheduled to run on another CPU but is waiting for other tasklets to finish, and you try to schedule the tasklet on a CPU that’s not currently processing tasklets, it will notice that the tasklet is already scheduled to run and not do anything. So tasklets are not so reliable when it comes to latencies. Hence, why I’m working on getting rid of them, since I don't believe they accomplish what people think they do.</span></span></span></div>
<div style="border: 0px; margin-bottom: 15px; padding: 0px; vertical-align: baseline;">
<span style="background-color: white;"><span style="font-family: Helvetica, Arial, sans-serif;"><span style="line-height: 19px;"><i> </i>I will discuss more about Bottom halves some other time, then I will discuss about workqueue too. Till then you can explore things from Linux Kernel Development. </span></span></span></div>
</div>
Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com0tag:blogger.com,1999:blog-4224221485098744558.post-58170530405684311782012-12-18T12:13:00.000+05:302012-12-18T12:16:44.220+05:30USB: A brief tutorial <div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">If you need your embedded application to talk to a PC then increasingly the way to go is USB. Partly this is because of the performance it can supply but also for the very practical reason that many PCs and most portables no longer have parallel or serial ports. But unlike the good <b>old parallel or serial cables these interfaces are far from simple to implement, debug or program</b>. Here is a quick summary of some terms you might encounter during USB Driver.</span><br />
<span style="background-color: white;"><span style="font-family: arial, helvetica, sans-serif; font-size: 14px;"><br /></span>
</span><br />
<h2 style="font-family: arial, helvetica, sans-serif; font-size: 1.2em; font-weight: bolder; margin-bottom: 0px; margin-top: 0px;">
<span style="background-color: white;">
The Standards</span></h2>
<div>
<span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">I will not go into the history, but if we take a brief look on USB, the basic standards are as below :</span></div>
<h3 style="font-family: arial, helvetica, sans-serif; font-size: 1em; font-weight: bolder; margin-bottom: 0px; margin-top: 0px;">
<span style="background-color: white;">
USB 1.1</span></h3>
<div style="margin-bottom: 10px;">
<span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">The original USB standard provides a fast Master/Slave interface using a tiered star topology supporting up to 127 devices with up to 6 tiers (hubs). A PC is normally the master or <b>Host</b> and each of the peripherals linked to it act as slaves or <b>Devices</b>. One of the aims of the design was to minimise the complexity of the Devices by doing as much in the Host as possible. Data transfer rates are defined in the specification as - <b>Low Speed 1.5 Mbits/sec</b> and <b>Full Speed 12 Mbits/sec</b> and the maximum length of each cable section is 5 metres. The USB specification allows each device to take up to 500mA of power (limited to 100mA during startup).</span></div>
<h3 style="font-family: arial, helvetica, sans-serif; font-size: 1em; font-weight: bolder; margin-bottom: 0px; margin-top: 0px;">
<span style="background-color: white;">
USB 2.0</span></h3>
<div style="font-family: arial, helvetica, sans-serif; margin-bottom: 10px;">
<span style="background-color: white;">There are some minor variations from USB 1.1 within the USB 2.0 specification and since USB 2.0s inception most interfaces have been designed to conform to the USB 2.0 standard. The 2.0 specification is a superset of 1.1 and the major functional difference which is the addition of a <b>High Speed 480 Mbits/sec </b>data transfer mode. Be warned, however, that the Spec does allow a product (eg an interface chip) to say that it is "USB 2.0 compatible" without necessarily implying that it actually implements the High Speed mode.</span></div>
<h3 style="font-family: arial, helvetica, sans-serif; font-size: 1em; font-weight: bolder; margin-bottom: 0px; margin-top: 0px;">
<span style="background-color: white;">
USB 3.0</span></h3>
<div style="margin-bottom: 10px;">
<span style="background-color: white;"><span style="font-family: arial, helvetica, sans-serif;">Released in 2008 with motherboards and products appearing in 2010. It has been designed to be backward compatible with 2.0 with a socket that will fit most combinations of legacy plugs and as well as supplying more power (900mA) it also adds a </span><b style="font-family: arial, helvetica, sans-serif;">Super Speed >4.8 Gbits/sec </b><span style="font-family: arial, helvetica, sans-serif;">data transfer mode so should be able to deliver 400 MBytes/sec after protocol overheads. It is becoming popular for use with external hard disks and other high speed applications.</span></span></div>
<h3 style="font-family: arial, helvetica, sans-serif; font-size: 1em; font-weight: bolder; margin-bottom: 0px; margin-top: 0px;">
<span style="background-color: white;">
Wireless USB</span></h3>
<div style="font-family: arial, helvetica, sans-serif; margin-bottom: 10px;">
<span style="background-color: white;">A short range high speed radio communications protocol ( 480 Mbit/s up to 3 m and 110 Mbit/s up to 10 ) which seems to aim to compete with Bluetooth.</span></div>
<div style="font-family: arial, helvetica, sans-serif; font-size: 0.9em; margin-bottom: 10px;">
<span style="background-color: white;"><br /></span></div>
<div style="font-family: arial, helvetica, sans-serif; font-size: 0.9em; margin-bottom: 10px;">
</div>
<h2 style="font-size: 1.2em; font-weight: bolder; margin-bottom: 0px; margin-top: 0px;">
<span style="background-color: white;">
Signals, Throughput & Protocol</span></h2>
<div style="margin-bottom: 10px;">
<span style="background-color: white;">USB 1 & 2 cables use 4 lines - Power, Ground and a twisted pair differential +/- data lines using NRZI encoding. The USB connectors are designed so that power and ground are applied before the signal lines are connected. When the Host powers up it polls each of the Slave devices in turn (using the reserved address 0), it assigns each one a unique address and finds out from each device what its Speed is and the and type of data transfer it wishes to perform. This process is called <b>enumeration</b> and it also takes place whenever a device is plugged into an active network. The connectors design (contact to power then signal) along with the process of enumeration and a lot of host software allows devices to be described as "Plug-and-Play".</span></div>
<div style="margin-bottom: 10px;">
<span style="background-color: white;"> A typical transaction will consist of a number of packets - a <b>token</b> indicating the type of data that the Host is sending or requiring, the data and in some cases an acknowledgement. Each packet is preceded by a sync field and followed by an end of packet marker.</span></div>
<div style="margin-bottom: 10px;">
<span style="background-color: white;">These transactions are used to provide four basic data transfer mechanisms:</span></div>
<div style="margin-bottom: 10px;">
<span style="background-color: white;"><b>Control </b>- used by the Host to send commands or query parameters. Packet lengths are 8 bytes for Low speed, 8-64 for Full and 64 for High Speed devices.</span></div>
<div style="margin-bottom: 10px;">
<span style="background-color: white;"><b>Interrupt</b> - badly named it is in fact a polled message from the Host which has to request specific data of the Device. Used by Devices which will be sending small amounts of data (e.g. mice or keyboards).</span></div>
<div style="margin-bottom: 10px;">
<span style="background-color: white;"><b>Bulk</b> - Used by Devices that send or receive data in quantity such as a printer. Variable length blocks of data are sent or requested by the Host (max length is 64-byte- full speed, 512 -high speed), are verified with a CRC and their receipt is acknowledged. This mechanism is not used by time critical peripherals as it takes whatever bandwidth is left by the other mechanisms.</span></div>
<div style="margin-bottom: 10px;">
<span style="background-color: white;"><b>Isochronous</b> - Used for devices that stream data in real time without any error recovery such as audio channels. For them losing some data occasionally is better than the glitch resulting from a re-transmit. Packet sizes can be up to 1024 bytes.</span></div>
<span style="background-color: white;"><br />
</span><br />
<div style="margin-bottom: 10px;">
<span style="background-color: white;">As devices are enumerated, the host keeps track of the total bandwidth that the isochronous and interrupt devices request. They can consume up to 90 percent of the bandwidth that is available. After 90 percent is used up, the host denies access to any other isochronous or interrupt devices. Control packets and Bulk Transfers are guaranteed at least 10 percent with Control taking priority.</span></div>
<div style="margin-bottom: 10px;">
<span style="background-color: white;">The USB Host does this by dividing the available bandwidth into frames containing 1,500 bytes, with a new frame starting every millisecond. During a frame, isochronous and interrupt transfers get a slot so they are guaranteed the bandwidth they need. Control and then Bulk transfers use whatever time is left.</span></div>
<div style="margin-bottom: 10px;">
<span style="background-color: white;"><br /></span></div>
<div style="margin-bottom: 10px;">
</div>
<h3 style="font-family: arial, helvetica, sans-serif; font-size: 1em; margin-bottom: 0px; margin-top: 0px;">
<span style="background-color: white;">
Throughput for 2.0<br /><span style="font-weight: bolder;"> </span></span></h3>
<div align="center" style="font-family: arial, helvetica, sans-serif;">
<table border="1" bordercolor="#000000" cellspacing="0" id="table2" style="width: 80%px;"><tbody>
<tr><td align="center" colspan="4"><b style="background-color: white;">Maximum Theoretical transfer rates</b></td></tr>
<tr><td align="center"><b style="background-color: white;">Transfer Type</b></td><td align="center"><b style="background-color: white;">Low-speed</b></td><td align="center"><b style="background-color: white;">Full-Speed (all Kbytes/sec)</b></td><td align="center"><b style="background-color: white;">High-speed</b></td></tr>
<tr><td align="center"><span style="background-color: white;">Control</span></td><td align="center"><span style="background-color: white;">24</span></td><td align="center"><span style="background-color: white;">832</span></td><td align="center"><span style="background-color: white;">15,872</span></td></tr>
<tr><td align="center"><span style="background-color: white;">Interrupt</span></td><td align="center"><span style="background-color: white;">0.8</span></td><td align="center"><span style="background-color: white;">64</span></td><td align="center"><span style="background-color: white;">24,576</span></td></tr>
<tr><td align="center"><span style="background-color: white;">Bulk</span></td><td align="center"><span style="background-color: white;">NA</span></td><td align="center"><span style="background-color: white;">1,216</span></td><td align="center"><span style="background-color: white;">53,248</span></td></tr>
<tr><td align="center"><span style="background-color: white;">Isochronous</span></td><td align="center"><span style="background-color: white;">NA</span></td><td align="center"><span style="background-color: white;">1,023</span></td><td align="center"><span style="background-color: white;">24,576</span></td></tr>
</tbody></table>
</div>
<div style="font-family: arial, helvetica, sans-serif; margin-bottom: 10px;">
<span style="background-color: white;"><b><br />But note that</b> in practice the actual throughput achieved also depends on the host's performance which may only allow 70% of the highest values to be achieved. Although if we have one highest priority application which is using USB, then we can achieve the 90% or more of the highest value.</span></div>
<div style="font-family: arial, helvetica, sans-serif; margin-bottom: 10px;">
<span style="background-color: white;"><br /></span></div>
<div style="font-family: arial, helvetica, sans-serif; margin-bottom: 10px;">
</div>
<h3 style="font-size: 1em; font-weight: bolder; margin-bottom: 0px; margin-top: 0px;">
<span style="background-color: white;">
Protocol:</span></h3>
<div>
<span style="background-color: white;"><br /></span></div>
<div style="margin-bottom: 10px;">
<span style="background-color: white;">When the USB Device is enumerated as well as getting an address from the Host it presents the Host with a good deal of information about itself in the form of a series of descriptors.</span></div>
<div style="margin-bottom: 10px;">
<span style="background-color: white;">1.The <b>Device Descriptor</b> tells the Host what the Vendor and Product ID are (which the Host may use to load a driver)</span><br />
<span style="background-color: white;"> 1.1The <b>Configuration Descriptors</b> (there may be a number of these - the Host chooses one) offers a power consumption value</span><br />
<span style="background-color: white;"> 1.1.1 and a number of <b>Interface Descriptors</b> (a device may be a printer/scanner/fax with separate descriptors)</span><br />
<span style="background-color: white;"> 1.1.1.1each of these will define a number of <b>Endpoints </b>which are the sources and destinations for data transfers</span><br />
<span style="background-color: white;"> 1.1.1.1.1The <b>Endpoint</b> Descriptors provide the following detail ---</span><br />
<span style="background-color: white;"> 1.1.1.1.1.1transfer type (Bulk, Interrupt, Isochronous), direction, packet sizes, bandwidth requirement and repeat interval.</span></div>
<div style="margin-bottom: 10px;">
<span style="background-color: white;">There can be 4 Endpoints for Low speed devices 16 in and 16 out for Full and High speed devices- these include the<b> mandatory Endpoint 0.</b> </span></div>
<div style="margin-bottom: 10px;">
<span style="background-color: white;">But what is an Endpoint ? Wikipedia defines it as "<b>the the identifier for the entity on one end of a transport layer connection</b>" in practice it may be a register in the device or a buffer into which data (<b>"addressed" to the Endpoint</b>) is going to be transferred. Those familiar with TCP/IP nomenclature will see that it resembles what is referred to in that <b>software as a Socket</b>.</span></div>
<div style="margin-bottom: 10px;">
<span style="background-color: white;">Logically each USB peripheral sets up a one to one link between endpoints on the device and applications software. The driver software and the interfaces at each end translate between a software call on the host to a peripheral endpoint and the required message details. The host's application software simply moves data to or from the endpoint on the peripheral without needing to know the connection details.</span></div>
<div style="margin-bottom: 10px;">
<span style="background-color: white;">The Host software does this via pathways known as <b>Pipes </b>between it and the Endpoints There are two types of pipe defined within the specification...</span></div>
<blockquote>
<div style="margin-bottom: 10px;">
<span style="background-color: white;"><b>Message pipes</b> which are bidirectional, for which the USB standard defines the format and which can only be used by Control Transfers</span></div>
<div style="margin-bottom: 10px;">
<span style="background-color: white;"><b>Stream pipes</b> which can be In or Out and which can be used by Interrupt, Bulk and Isochronous Transfers. The USB standard does not determine the layout of the data in these streams (of course the messages passing the data across the bus are structured and contain endpoint addresses but these fields are stripped out before delivery to the pipe).</span></div>
</blockquote>
<div style="margin-bottom: 10px;">
<span style="background-color: white;">All the above are specified by the USB protocol so that devices will operate in a uniform manner both at the Bus level but also at the next level up the Transport Level.</span></div>
<div style="margin-bottom: 10px;">
<span style="background-color: white;">Hopefully your USB interface chip will handle all the detailed operations that make up the actions we have discussed above however you will need to know these terms in order to select the appropriate Transfer mechanism, set your Device up correctly and to use the Pipe to transfer your data - not to mention having an idea of what is going on when you get an error message.</span></div>
<div style="margin-bottom: 10px;">
<span style="background-color: white;"><br /></span></div>
<div style="margin-bottom: 10px;">
</div>
<h2 style="font-size: 1.2em; font-weight: bolder; margin-bottom: 0px; margin-top: 0px;">
<span style="background-color: white;">
Devices, Hosts and On-The-Go</span></h2>
<h3 style="font-size: 1em; font-weight: bolder; margin-bottom: 0px; margin-top: 0px;">
<span style="background-color: white;">
USB Device</span></h3>
<div style="margin-bottom: 10px;">
<span style="background-color: white;">Most early on-chip USB interfaces and USB interface chips provided support allowing your embedded system to connect to the USB as a Device.</span></div>
<h3 style="font-size: 1em; font-weight: bolder; margin-bottom: 0px; margin-top: 0px;">
<span style="background-color: white;">
USB Host</span></h3>
<div style="margin-bottom: 10px;">
<span style="background-color: white;">The Master for the transaction - may be a PC but your application will have to be Master if you want to plug a USB memory stick into it and read the files off the stick. Increasingly interfaces capable of being Host are being incorporated into Microcontroller chips.</span></div>
<h3 style="font-size: 1em; font-weight: bolder; margin-bottom: 0px; margin-top: 0px;">
<span style="background-color: white;">
On-The-Go OTG</span></h3>
<div style="margin-bottom: 10px;">
<span style="background-color: white;">The initial USB standard assumed the presence of a Host - the PC. However it has become important to connect units which may, under some circumstances be a Device but may be required under others to be a Host. For example a Printer is normally happy to be a Device when connected to a PC but may need to be connected to a Camera in the absence of a PC when the Printer will need to be the Host. The OTG protocol provides an arbitration mechanism that allows units to negotiate who is going to be Host. OTG introduces an additional data pin ID that determines the initial status for the Host/Device negotiation. OTG products may also be known as Dual Role Devices.</span></div>
<div style="margin-bottom: 10px;">
<span style="background-color: white;"><br /></span></div>
<div style="margin-bottom: 10px;">
<span style="background-color: white;"><br /></span></div>
<span style="background-color: white;"><br />
<br />
</span><br />
<div style="font-family: arial, helvetica, sans-serif; font-size: 0.9em; margin-bottom: 10px;">
<span style="background-color: white;"><br /></span></div>
<div style="font-family: arial, helvetica, sans-serif; font-size: 0.9em; margin-bottom: 10px;">
<span style="background-color: white;"><br /></span></div>
<div>
<span style="background-color: white;"><br /></span></div>
<span style="background-color: white;"><br /></span>
</div>
Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com0tag:blogger.com,1999:blog-4224221485098744558.post-8985163200151504002012-10-10T00:25:00.002+05:302012-10-10T00:25:50.523+05:30Linux Commands <div dir="ltr" style="text-align: left;" trbidi="on">
<h1 style="clear: both; line-height: 1em; text-align: -webkit-auto;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">An A-Z Index of the <span class="grn">Bash</span> command line for Linux. <span style="text-align: left;">For more detail of this command type man and command name on terminal. </span></span></h1>
<pre style="text-align: -webkit-auto;"><span style="font-family: Arial, Helvetica, sans-serif;"> </span><span style="font-family: Arial, Helvetica, sans-serif;"> alias Create an alias •</span></pre>
<pre style="text-align: -webkit-auto;"><span style="font-family: Arial, Helvetica, sans-serif;"> apropos Search Help manual pages (man -k)
apt-get Search for and install software packages (Debian/Ubuntu)
aptitude Search for and install software packages (Debian/Ubuntu)
aspell Spell Checker
awk Find and Replace text, database sort/validate/index
basename Strip directory and suffix from filenames
bash GNU Bourne-Again SHell
bc Arbitrary precision calculator language
bg Send to background
break Exit from a loop •
builtin Run a shell builtin
bzip2 Compress or decompress named file(s)
cal Display a calendar
case Conditionally perform a command
cat Concatenate and print (display) the content of files
cd Change Directory
cfdisk Partition table manipulator for Linux
chgrp Change group ownership
chmod Change access permissions
chown Change file owner and group
chroot Run a command with a different root directory
chkconfig System services (runlevel)
cksum Print CRC checksum and byte counts
clear Clear terminal screen
cmp Compare two files
comm Compare two sorted files line by line
command Run a command - ignoring shell functions •
continue Resume the next iteration of a loop •
cp Copy one or more files to another location
cron Daemon to execute scheduled commands
crontab Schedule a command to run at a later time
csplit Split a file into context-determined pieces
cut Divide a file into several parts
date Display or change the date & time
dc Desk Calculator
dd Convert and copy a file, write disk headers, boot records
ddrescue Data recovery tool
declare Declare variables and give them attributes •
df Display free disk space
diff Display the differences between two files
diff3 Show differences among three files
dig DNS lookup
dir Briefly list directory contents
dircolors Colour setup for `ls'
dirname Convert a full pathname to just a path
dirs Display list of remembered directories
dmesg Print kernel & driver messages
du Estimate file space usage
echo Display message on screen •
egrep Search file(s) for lines that match an extended expression
eject Eject removable media
enable Enable and disable builtin shell commands •
env Environment variables
ethtool Ethernet card settings
eval Evaluate several commands/arguments
exec Execute a command
exit Exit the shell
expect Automate arbitrary applications accessed over a terminal
expand Convert tabs to spaces
export Set an environment variable
expr Evaluate expressions
false Do nothing, unsuccessfully
fdformat Low-level format a floppy disk
fdisk Partition table manipulator for Linux
fg Send job to foreground
fgrep Search file(s) for lines that match a fixed string
file Determine file type
find Search for files that meet a desired criteria
fmt Reformat paragraph text
fold Wrap text to fit a specified width.
for Expand <var>words</var>, and execute <var>commands</var>
format Format disks or tapes
free Display memory usage
fsck File system consistency check and repair
ftp File Transfer Protocol
function Define Function Macros
fuser Identify/kill the process that is accessing a file
gawk Find and Replace text within file(s)
getopts Parse positional parameters
grep Search file(s) for lines that match a given pattern
groupadd Add a user security group
groupdel Delete a group
groupmod Modify a group
groups Print group names a user is in
gzip Compress or decompress named file(s)
hash Remember the full pathname of a name argument
head Output the first part of file(s)
help Display help for a built-in command •
history Command History
hostname Print or set system name
iconv Convert the character set of a file
id Print user and group id's
if Conditionally perform a command
ifconfig Configure a network interface
ifdown Stop a network interface
ifup Start a network interface up
import Capture an X server screen and save the image to file
install Copy files and set attributes
jobs List active jobs •
join Join lines on a common field
kill Stop a process from running
killall Kill processes by name
less Display output one screen at a time
let Perform arithmetic on shell variables •
ln Make links between files
local Create variables •
locate Find files
logname Print current login name
logout Exit a login shell •
look Display lines beginning with a given string
lpc Line printer control program
lpr Off line print
lprint Print a file
lprintd Abort a print job
lprintq List the print queue
<a href="http://ss64.com/bash/lprm.html" style="color: #711b8d; text-decoration: none;">lprm</a> Remove jobs from the print queue
<a href="http://ss64.com/bash/ls.html" style="color: #711b8d; text-decoration: none;">ls</a> List information about file(s)
<a href="http://ss64.com/bash/lsof.html" style="color: #711b8d; text-decoration: none;">lsof</a> List open files
make Recompile a group of programs
man Help manual
mkdir Create new folder(s)
mkfifo Make FIFOs (named pipes)
mkisofs Create an hybrid ISO9660/JOLIET/HFS filesystem
mknod Make block or character special files
more Display output one screen at a time
mount Mount a file system
mtools Manipulate MS-DOS files
mtr Network diagnostics (traceroute/ping)
mv Move or rename files or directories
mmv Mass Move and rename (files)
netstat Networking information
nice Set the priority of a command or job
nl Number lines and write files
nohup Run a command immune to hangups
notify-send Send desktop notifications
nslookup Query Internet name servers interactively
open Open a file in its default application
op Operator access
passwd Modify a user password
paste Merge lines of files
pathchk Check file name portability
ping Test a network connection
pkill Stop processes from running
popd Restore the previous value of the current directory
pr Prepare files for printing
printcap Printer capability database
printenv Print environment variables
printf Format and print data •
ps Process status
pushd Save and then change the current directory
pwd Print Working Directory
quota Display disk usage and limits
quotacheck Scan a file system for disk usage
quotactl Set disk quotas
ram ram disk device
rcp Copy files between two machines
read Read a line from standard input •
readarray Read from stdin into an array variable •
readonly Mark variables/functions as readonly
reboot Reboot the system
rename Rename files
renice Alter priority of running processes
remsync Synchronize remote files via email
return Exit a shell function
rev Reverse lines of a file
rm Remove files
rmdir Remove folder(s)
rsync Remote file copy (Synchronize file trees)
screen Multiplex terminal, run remote shells via ssh
scp Secure copy (remote file copy)
sdiff Merge two files interactively
sed Stream Editor
select Accept keyboard input
seq Print numeric sequences
set Manipulate shell variables and functions
sftp Secure File Transfer Program
shift Shift positional parameters
shopt Shell Options
shutdown Shutdown or restart linux
sleep Delay for a specified time
slocate Find files
sort Sort text files
source Run commands from a file `.'
split Split a file into fixed-size pieces
ssh Secure Shell client (remote login program)
strace Trace system calls and signals
su Substitute user identity
sudo Execute a command as another user
sum Print a checksum for a file
suspend Suspend execution of this shell •
symlink Make a new name for a file
sync Synchronize data on disk with memory
tail Output the last part of file
tar Tape ARchiver
tee Redirect output to multiple files
test Evaluate a conditional expression
time Measure Program running time
times User and system times
touch Change file timestamps
top List processes running on the system
traceroute Trace Route to Host
trap Run a command when a signal is set(bourne)
tr Translate, squeeze, and/or delete characters
true Do nothing, successfully
tsort Topological sort
tty Print filename of terminal on stdin
type Describe a command •
ulimit Limit user resources •
umask Users file creation mask
umount Unmount a device
unalias Remove an alias •
uname Print system information
unexpand Convert spaces to tabs
uniq Uniquify files
units Convert units from one scale to another
unset Remove variable or function names
unshar Unpack shell archive scripts
until Execute commands (until error)
uptime Show uptime
useradd Create new user account
userdel Delete a user account
usermod Modify user account
users List users currently logged in
uuencode Encode a binary file
uudecode Decode a file created by uuencode
v Verbosely list directory contents (`ls -l -b')
vdir Verbosely list directory contents (`ls -l -b')
vi Text Editor
vmstat Report virtual memory statistics
wait Wait for a process to complete •
watch Execute/display a program periodically
wc Print byte, word, and line counts
whereis Search the user's $path, man pages and source files for a program
which Search the user's $path for a program file
while Execute commands
who Print all usernames currently logged in
whoami Print the current user id and name (`id -un')
wget Retrieve web pages or files via HTTP, HTTPS or FTP
write Send a message to another user
xargs Execute utility, passing constructed argument list(s)
xdg-open Open a file or URL in the user's preferred application
yes Print a string until interrupted
</span></pre>
</div>
Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com0tag:blogger.com,1999:blog-4224221485098744558.post-73333428836824963182012-10-09T17:10:00.004+05:302012-10-09T17:11:50.166+05:30Redirection in Linux<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="sect2" style="background-color: white; text-align: -webkit-auto;">
<h2 class="sect2">
What are standard input and standard output?</h2>
Most Linux commands read input, such as a file or another attribute for the command, and write output. By default, input is being given with the keyboard, and output is displayed on your screen. Your keyboard is your <em>standard input</em> (stdin) device, and the screen or a particular terminal window is the <em>standard output</em> (stdout) device.<br />
However, since Linux is a flexible system, these default settings don't necessarily have to be applied. The standard output, for example, on a heavily monitored server in a large environment may be a printer.</div>
<div class="sect2" style="background-color: white; text-align: -webkit-auto;">
<h2 class="sect2">
<a href="http://www.blogger.com/blogger.g?blogID=4224221485098744558" name="sect_05_01_02"></a>The redirection operators</h2>
<div class="sect3">
<h3 class="sect3">
<a href="http://www.blogger.com/blogger.g?blogID=4224221485098744558" name="sect_05_01_02_01"></a>Output redirection with > and |</h3>
Sometimes you will want to put output of a command in a file, or you may want to issue another command on the output of one command. This is known as redirecting output. Redirection is done using either the <span class="QUOTE">">"</span>(greater-than symbol), or using the <span class="QUOTE">"|"</span> (pipe) operator which sends the standard output of one command to another command as standard input.<br />
As we saw before, the <b class="command">cat</b> command concatenates files and puts them all together to the standard output. By redirecting this output to a file, this file name will be created - or overwritten if it already exists, so take care.<br />
<table bgcolor="#E0E0E0" border="0" style="width: 100%px;"><tbody>
<tr><td><span style="color: black;"></span><br />
<pre class="screen"><span style="color: black;"><tt class="prompt">vineet:~></tt> <b class="command">cat test1</b>
Hello to world
<tt class="prompt">vineet:~></tt> <b class="command">cat test2</b>
Bye to world
<tt class="prompt">vineet:~></tt> <b class="command">cat test1 test2 > test3</b>
<tt class="prompt">vineet:~></tt> <b class="command">cat test3</b>
Hello to world
Bye to world</span></pre>
<span style="color: black;">
</span></td></tr>
</tbody></table>
<div class="warning">
<br />
<table border="0" class="warning" style="width: 100%px;"><tbody>
<tr><td align="CENTER" valign="TOP" width="25"><br /></td><th align="LEFT" valign="CENTER"><b>Don't overwrite!</b></th></tr>
<tr><td></td><td align="LEFT" valign="TOP">Be careful not to overwrite existing (important) files when redirecting output. Many shells, including <span class="application">Bash</span>, have a built-in feature to protect you from that risk: <b class="command">noclobber</b>. See the <span class="application">Info</span> pages for more information. In<span class="application">Bash</span>, you would want to add the <b class="command">set <tt class="option">-o</tt> <tt class="parameter"><i>noclobber</i></tt></b> command to your <tt class="filename">.bashrc</tt> configuration file in order to prevent accidental overwriting of files.</td></tr>
</tbody></table>
</div>
Redirecting <span class="QUOTE">"nothing"</span> to an existing file is equal to emptying the file:<br />
<table bgcolor="#E0E0E0" border="0" style="width: 100%px;"><tbody>
<tr><td><span style="color: black;"></span><br />
<pre class="screen"><span style="color: black;"><tt class="prompt">vineet:~></tt> <b class="command">ls -l list</b>
-rw-rw-r-- 1 root root 117 Apr 2 18:09 list
<tt class="prompt">vineet:~></tt> <b class="command">> list</b>
<tt class="prompt">nancy:~></tt> <b class="command">ls -l list</b>
-rw-rw-r-- 1 root root 0 Apr 4 12:01 list
</span></pre>
<span style="color: black;">
</span></td></tr>
</tbody></table>
This process is called <em>truncating</em>.<br />
The same redirection to an nonexistent file will create a new empty file with the given name:<br />
<table bgcolor="#E0E0E0" border="0" style="width: 100%px;"><tbody>
<tr><td><span style="color: black;"></span><br />
<pre class="screen"><span style="color: black;"><tt class="prompt">vineet:~></tt> <b class="command">ls -l newlist</b>
ls: newlist: No such file or directory
<tt class="prompt">vineet:~></tt> <b class="command">> newlist</b>
<tt class="prompt">vinnet:~></tt> <b class="command">ls -l newlist</b>
-rw-rw-r-- 1 vineet vineet 0 Apr 4 12:05 newlist
</span></pre>
<span style="color: black;">
</span></td></tr>
</tbody></table>
Some examples using piping of commands:<br />
To find a word within some text, display all lines matching <span class="QUOTE">"pattern1"</span>, and exclude lines also matching <span class="QUOTE">"pattern2"</span> from being displayed:<br />
<b class="command">grep <tt class="parameter"><i>pattern1</i></tt> <tt class="filename">file</tt> | grep <tt class="option">-v</tt> <tt class="parameter"><i>pattern2</i></tt></b><br />
To display output of a directory listing one page at a time:<br />
<b class="command">ls <tt class="option">-la</tt> | less</b><br />
To find a file in a directory:<br />
<b class="command">ls <tt class="option">-l</tt> | grep <tt class="parameter"><i>part_of_file_name</i></tt></b></div>
<div class="sect3">
<h3 class="sect3">
Combining redirections</h3>
</div>
<div class="sect3">
The following example combines input and output redirection. The file <tt class="filename">text.txt</tt> is first checked for spelling mistakes, and the output is redirected to an error log file:<br />
<b class="command">spell < <tt class="filename">text.txt</tt> > <tt class="filename">error.log</tt></b><br />
The following command lists all commands that you can issue to examine another file when using <b class="command">less</b>:<br />
<table bgcolor="#E0E0E0" border="0" style="width: 100%px;"><tbody>
<tr><td><span style="color: black;"></span><br />
<pre class="screen"><span style="color: black;"><tt class="prompt">vineet:~></tt> <b class="command">less --help | grep -i examine</b>
:e [file] Examine a new file.
:n * Examine the (N-th) next file from the command line.
:p * Examine the (N-th) previous file from the command line.
:x * Examine the first (or N-th) file from the command line.
</span></pre>
<span style="color: black;">
</span></td></tr>
</tbody></table>
The <tt class="option">-i</tt> option is used for case-insensitive searches - remember that UNIX systems are very case-sensitive.<br />
If you want to save output of this command for future reference, redirect the output to a file:<br />
<table bgcolor="#E0E0E0" border="0" style="width: 100%px;"><tbody>
<tr><td><span style="color: black;"></span><br />
<pre class="screen"><span style="color: black;"><tt class="prompt">vineet:~></tt> <b class="command">less --help | grep -i examine > examine-files-in-less</b>
<tt class="prompt">vineet:~></tt> <b class="command">cat examine-files-in-less</b>
:e [file] Examine a new file.
:n * Examine the (N-th) next file from the command line.
:p * Examine the (N-th) previous file from the command line.
:x * Examine the first (or N-th) file from the command line.
</span></pre>
<span style="color: black;">
</span></td></tr>
</tbody></table>
Output of one command can be piped into another command virtually as many times as you want, just as long as these commands would normally read input from standard input and write output to the standard output. Sometimes they don't, but then there may be special options that instruct these commands to behave according to the standard definitions; so read the documentation (man and <span class="application">Info</span> pages) of the commands you use if you should encounter errors.<br />
Again, make sure you don't use names of existing files that you still need. Redirecting output to existing files will replace the content of those files.</div>
<div class="sect3">
<h3 class="sect3">
The >> operator</h3>
Instead of overwriting file data, you can also append text to an existing file using two subsequent greater-than signs:<br />
Example:<br />
<table bgcolor="#E0E0E0" border="0" style="width: 100%px;"><tbody>
<tr><td><span style="color: black;"></span><br />
<pre class="screen"><span style="color: black;"><tt class="prompt">vineet:~></tt> <b class="command">cat <tt class="filename">wishlist</tt></b>
more money
less work
<tt class="prompt">vineet:~></tt> <b class="command">date >> <tt class="filename">wishlist</tt></b>
<tt class="prompt">vineet:~></tt> <b class="command">cat <tt class="filename">wishlist</tt></b>
more money
less work
Tue Oct 9 17:06:55 IST 2012
</span></pre>
<span style="color: black;">
</span></td></tr>
</tbody></table>
<br />
The <b class="command">date</b> command would normally put the last line on the screen; now it is appended to the file <tt class="filename">wishlist</tt>.<br />
<br />
<br />
<br />
<div class="sect2">
<h2 class="sect2">
Use of file descriptors</h2>
There are three types of I/O, which each have their own identifier, called a file descriptor:<br />
<br />
<ul>
<li>standard input: 0</li>
<li>standard output: 1</li>
<li>standard error: 2</li>
</ul>
In the following descriptions, if the file descriptor number is omitted, and the first character of the redirection operator is <, the redirection refers to the standard input (file descriptor 0). If the first character of the redirection operator is >, the redirection refers to the standard output (file descriptor 1).<br />
Some practical examples will make this more clear:<br />
<b class="command">ls > <tt class="filename">dirlist</tt> 2>&1</b><br />
will direct both standard output and standard error to the file <tt class="filename">dirlist</tt>, while the command<br />
<b class="command">ls 2>&1 > <tt class="filename">dirlist</tt></b><br />
will only direct standard output to <tt class="filename">dirlist</tt>. This can be a useful option for programmers.<br />
. The example below demonstrates this:<br />
<table bgcolor="#E0E0E0" border="0" style="width: 100%px;"><tbody>
<tr><td><span style="color: black;"></span><br />
<pre class="screen"><span style="color: black;"><tt class="prompt">[vineet@vineet]$ </tt><b class="command">ls 2> <tt class="filename">tmp</tt></b>
<tt class="prompt">[vineet@vineet]$ </tt><b class="command">ls -l <tt class="filename">tmp</tt></b>
-rw-rw-r-- 1 vineet vineet 0 Sept 7 12:58 tmp
<tt class="prompt">[vineet@vineet]$ </tt><b class="command">ls 2 > <tt class="filename">tmp</tt></b>
ls: 2: No such file or directory
</span></pre>
<span style="color: black;">
</span></td></tr>
</tbody></table>
The first command that <i>vineet</i> executes is correct (eventhough no errors are generated and thus the file to which standard error is redirected is empty). The second command expects that <tt class="filename">2</tt> is a file name, which does not exist in this case, so an error is displayed.<br />
All these features are explained in detail in the Bash Info pages.</div>
<div class="sect2">
<h2 class="sect2">
Examples</h2>
<div class="sect3">
<h3 class="sect3">
Writing to output and files simultaneously</h3>
</div>
<div class="sect3">
You can use the <b class="command">tee</b> command to copy input to standard output and one or more output files in one move. Using the <tt class="option">-a</tt> option to <b class="command">tee</b> results in appending input to the file(s). This command is useful if you want to both see and save output. The <b class="command">></b> and <b class="command">>></b> operators do not allow to perform both actions simultaneously.<br />
This tool is usually called on through a pipe (<b class="command">|</b>), as demonstrated in the example below:<br />
<table bgcolor="#E0E0E0" border="0" style="width: 100%px;"><tbody>
<tr><td><span style="color: black;"></span><br />
<pre class="screen"><span style="color: black;">[vineet@vineet ~]$ <b class="command">date | tee <tt class="filename">file1 file2</tt></b>
<pre class="screen">Tue Oct 9 17:12:17 IST 2012
</pre>
<div>
</div>
<tt class="prompt">[vineet@vineet ~]$ </tt> <b class="command">cat <tt class="filename">file1</tt></b>
<pre class="screen">Tue Oct 9 17:12:17 IST 2012
</pre>
<div>
</div>
<tt class="prompt">[vineet@vineet ~]$ </tt> <b class="command">cat <tt class="filename">file2</tt></b>
<pre class="screen">Tue Oct 9 17:12:17 IST 2012
</pre>
<div>
</div>
<tt class="prompt">[vineet@vineet ~]$ </tt> <b class="command">uptime | tee <tt class="option">-a</tt> <tt class="filename">file2</tt></b>
17:13:41 up 36 min, 2 users, load average: 0.27, 0.12, 0.14
<tt class="prompt">[vineet@vineet ~]$ </tt> <b class="command">cat <tt class="filename">file2</tt></b>
<pre class="screen">Tue Oct 9 17:12:17 IST 2012
</pre>
17:13:41 up 36 min, 2 users, load average: 0.27, 0.12, 0.14
</span></pre>
<span style="color: black;">
<div>
<br /></div>
</span></td></tr>
</tbody></table>
</div>
</div>
</div>
</div>
</div>
Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com0tag:blogger.com,1999:blog-4224221485098744558.post-14987485717891764712012-09-22T11:20:00.002+05:302012-09-22T11:20:53.825+05:30Linux Booting Process<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; margin-bottom: 1.571em; padding: 0px; text-align: -webkit-auto;">
Press the power button on your system, and after few moments you see the Linux login prompt.</div>
<div style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; margin-bottom: 1.571em; padding: 0px; text-align: -webkit-auto;">
Have you ever wondered what happens behind the scenes from the time you press the power button until the Linux login prompt appears?</div>
<div style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; margin-bottom: 1.571em; padding: 0px; text-align: -webkit-auto;">
The following are the 6 high level stages of a typical Linux boot process.</div>
<div style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; margin-bottom: 1.571em; padding: 0px; text-align: -webkit-auto;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMPujj1hVgc6maUKDNka_nFoJSuFivLLWIq24cIS70hHULGZYZC4auv7qC_wZ72PWIgeZCTvqTz1pa3rLwj2yv5GHNilga8I5GSnGpSmQ2zueA4YwoGNvUBIOLDaEabdMDUXafQ3dbwmxn/s1600/linux-boot-process.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="386" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMPujj1hVgc6maUKDNka_nFoJSuFivLLWIq24cIS70hHULGZYZC4auv7qC_wZ72PWIgeZCTvqTz1pa3rLwj2yv5GHNilga8I5GSnGpSmQ2zueA4YwoGNvUBIOLDaEabdMDUXafQ3dbwmxn/s400/linux-boot-process.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<h3 style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.286em; font-weight: normal; line-height: 22px; margin: 1.833em 0px 0.611em; padding: 0px; text-align: -webkit-auto;">
1. BIOS</h3>
<ul style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; list-style: square; margin: 0px 0px 1.571em 1.571em; padding: 0px; text-align: -webkit-auto;">
<li style="margin: 0px; padding: 0px;">BIOS stands for Basic Input/Output System</li>
<li style="margin: 0px; padding: 0px;">Performs some system integrity checks</li>
<li style="margin: 0px; padding: 0px;">Searches, loads, and executes the boot loader program.</li>
<li style="margin: 0px; padding: 0px;">It looks for boot loader in floppy, cd-rom, or hard drive. You can press a key (typically F12 of F2, but it depends on your system) during the BIOS startup to change the boot sequence.</li>
<li style="margin: 0px; padding: 0px;">Once the boot loader program is detected and loaded into the memory, BIOS gives the control to it.</li>
<li style="margin: 0px; padding: 0px;">So, in simple terms BIOS loads and executes the MBR boot loader.</li>
</ul>
<div style="text-align: -webkit-auto;">
<span style="color: #111111; font-family: Helvetica Neue, Helvetica, Arial, sans-serif;"><span style="font-size: 14px; line-height: 22px;"><br /></span></span></div>
<div style="text-align: -webkit-auto;">
<h3 style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.286em; font-weight: normal; line-height: 22px; margin: 1.833em 0px 0.611em; padding: 0px;">
2. MBR</h3>
<ul style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; list-style: square; margin: 0px 0px 1.571em 1.571em; padding: 0px;">
<li style="margin: 0px; padding: 0px;">MBR stands for Master Boot Record.</li>
<li style="margin: 0px; padding: 0px;">It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda</li>
<li style="margin: 0px; padding: 0px;">MBR is less than 512 bytes in size. This has three components 1) primary boot loader info in 1st 446 bytes 2) partition table info in next 64 bytes 3) mbr validation check in last 2 bytes.</li>
<li style="margin: 0px; padding: 0px;">It contains information about GRUB (or LILO in old systems).</li>
<li style="margin: 0px; padding: 0px;">So, in simple terms MBR loads and executes the GRUB boot loader.</li>
</ul>
<div>
<span style="color: #111111; font-family: Helvetica Neue, Helvetica, Arial, sans-serif;"><span style="font-size: 14px; line-height: 22px;"><br /></span></span></div>
<div>
<h3 style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.286em; font-weight: normal; line-height: 22px; margin: 1.833em 0px 0.611em; padding: 0px;">
3. GRUB</h3>
<ul style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; list-style: square; margin: 0px 0px 1.571em 1.571em; padding: 0px;">
<li style="margin: 0px; padding: 0px;">GRUB stands for Grand Unified Bootloader.</li>
<li style="margin: 0px; padding: 0px;">If you have multiple kernel images installed on your system, you can choose which one to be executed.</li>
<li style="margin: 0px; padding: 0px;">GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads the default kernel image as specified in the grub configuration file.</li>
<li style="margin: 0px; padding: 0px;">GRUB has the knowledge of the filesystem (the older Linux loader LILO didn’t understand filesystem).</li>
<li style="margin: 0px; padding: 0px;">Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this).</li>
</ul>
<div>
<span style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.286em; line-height: 22px;">4. Kernel</span></div>
<div>
<ul style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; list-style: square; margin: 0px 0px 1.571em 1.571em; padding: 0px;">
<li style="margin: 0px; padding: 0px;">Mounts the root file system as specified in the “root=” in grub.conf</li>
<li style="margin: 0px; padding: 0px;">Kernel executes the /sbin/init program</li>
<li style="margin: 0px; padding: 0px;">Since init was the 1st program to be executed by Linux Kernel, it has the process id (PID) of 1. Do a ‘ps -ef | grep init’ and check the pid.</li>
<li style="margin: 0px; padding: 0px;">initrd stands for Initial RAM Disk.</li>
<li style="margin: 0px; padding: 0px;">initrd is used by kernel as temporary root file system until kernel is booted and the real root file system is mounted. It also contains necessary drivers compiled inside, which helps it to access the hard drive partitions, and other hardware.</li>
</ul>
<h3 style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.286em; font-weight: normal; line-height: 22px; margin: 1.833em 0px 0.611em; padding: 0px;">
5. Init</h3>
<ul style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; list-style: square; margin: 0px 0px 1.571em 1.571em; padding: 0px;">
<li style="margin: 0px; padding: 0px;">Looks at the /etc/inittab file to decide the Linux run level.</li>
<li style="margin: 0px; padding: 0px;">Following are the available run levels<ul style="list-style: square; margin: 0px 0px 0px 1.571em; padding: 0px;">
<li style="margin: 0px; padding: 0px;">0 – halt</li>
<li style="margin: 0px; padding: 0px;">1 – Single user mode</li>
<li style="margin: 0px; padding: 0px;">2 – Multiuser, without NFS</li>
<li style="margin: 0px; padding: 0px;">3 – Full multiuser mode</li>
<li style="margin: 0px; padding: 0px;">4 – unused</li>
<li style="margin: 0px; padding: 0px;">5 – X11</li>
<li style="margin: 0px; padding: 0px;">6 – reboot</li>
</ul>
</li>
<li style="margin: 0px; padding: 0px;">Init identifies the default initlevel from /etc/inittab and uses that to load all appropriate program.</li>
<li style="margin: 0px; padding: 0px;">Execute ‘grep initdefault /etc/inittab’ on your system to identify the default run level</li>
<li style="margin: 0px; padding: 0px;">If you want to get into trouble, you can set the default run level to 0 or 6. Since you know what 0 and 6 means, probably you might not do that.</li>
<li style="margin: 0px; padding: 0px;">Typically you would set the default run level to either 3 or 5.</li>
</ul>
<h3 style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.286em; font-weight: normal; line-height: 22px; margin: 1.833em 0px 0.611em; padding: 0px;">
6. Runlevel programs</h3>
<ul style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; list-style: square; margin: 0px 0px 1.571em 1.571em; padding: 0px;">
<li style="margin: 0px; padding: 0px;">When the Linux system is booting up, you might see various services getting started. For example, it might say “starting sendmail …. OK”. Those are the runlevel programs, executed from the run level directory as defined by your run level.</li>
<li style="margin: 0px; padding: 0px;">Depending on your default init level setting, the system will execute the programs from one of the following directories.<ul style="list-style: square; margin: 0px 0px 0px 1.571em; padding: 0px;">
<li style="margin: 0px; padding: 0px;">Run level 0 – /etc/rc.d/rc0.d/</li>
<li style="margin: 0px; padding: 0px;">Run level 1 – /etc/rc.d/rc1.d/</li>
<li style="margin: 0px; padding: 0px;">Run level 2 – /etc/rc.d/rc2.d/</li>
<li style="margin: 0px; padding: 0px;">Run level 3 – /etc/rc.d/rc3.d/</li>
<li style="margin: 0px; padding: 0px;">Run level 4 – /etc/rc.d/rc4.d/</li>
<li style="margin: 0px; padding: 0px;">Run level 5 – /etc/rc.d/rc5.d/</li>
<li style="margin: 0px; padding: 0px;">Run level 6 – /etc/rc.d/rc6.d/</li>
</ul>
</li>
<li style="margin: 0px; padding: 0px;">Please note that there are also symbolic links available for these directory under /etc directly. So, /etc/rc0.d is linked to /etc/rc.d/rc0.d.</li>
<li style="margin: 0px; padding: 0px;">Under the /etc/rc.d/rc*.d/ directories, you would see programs that start with S and K.</li>
<li style="margin: 0px; padding: 0px;">Programs starts with S are used during startup. S for startup.</li>
<li style="margin: 0px; padding: 0px;">Programs starts with K are used during shutdown. K for kill.</li>
<li style="margin: 0px; padding: 0px;">There are numbers right next to S and K in the program names. Those are the sequence number in which the programs should be started or killed.</li>
<li style="margin: 0px; padding: 0px;">For example, S12syslog is to start the syslog deamon, which has the sequence number of 12. S80sendmail is to start the sendmail daemon, which has the sequence number of 80. So, syslog program will be started before sendmail.</li>
</ul>
<div>
<span style="color: #111111; font-family: Helvetica Neue, Helvetica, Arial, sans-serif;"><span style="font-size: 14px; line-height: 22px;"><br /></span></span></div>
</div>
<div>
<span style="color: #111111; font-family: Helvetica Neue, Helvetica, Arial, sans-serif;"><span style="font-size: 14px; line-height: 22px;"><br /></span></span></div>
<div>
<span style="color: #111111; font-family: Helvetica Neue, Helvetica, Arial, sans-serif;"><span style="font-size: 14px; line-height: 22px;"><br /></span></span></div>
</div>
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; margin-bottom: 1.571em; padding: 0px; text-align: -webkit-auto;">
<br /></div>
</div>
Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com0tag:blogger.com,1999:blog-4224221485098744558.post-24001765025775590832012-06-15T10:15:00.000+05:302012-06-15T10:15:07.353+05:30What is Zombie Process and Orphan Process?<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<h2 style="font-family: Verdana, sans-serif; margin: 0px 0px 10px; padding: 0px;">
<a class="h2heading h2" href="" name="Zombie" style="margin: 0px; padding: 0px;"><span style="font-size: small;">Zombie Process</span></a></h2>
<span style="background-color: white; font-family: Verdana, sans-serif;">On Unix operating systems, a zombie process or defunct process is a process that has completed execution but still has an entry in the process table, allowing the process that started it to read its exit status. In the term's colorful metaphor, the child process has died but has not yet been reaped. </span><br style="font-family: Verdana, sans-serif; margin: 0px; padding: 0px;" /><br style="font-family: Verdana, sans-serif; margin: 0px; padding: 0px;" /><span style="background-color: white; font-family: Verdana, sans-serif;">When a process ends, all of the memory and resources associated with it are deallocated so they can be used by other processes. However, the process's entry in the process table remains. The parent is sent a SIGCHLD signal indicating that a child has died; the handler for this signal will typically execute the wait system call, which reads the exit status and removes the zombie. The zombie's process ID and entry in the process table can then be reused. However, if a parent ignores the SIGCHLD, the zombie will be left in the process table. In some situations this may be desirable, for example if the parent creates another child process it ensures that it will not be allocated the same process ID. </span><br style="font-family: Verdana, sans-serif; margin: 0px; padding: 0px;" /><br style="font-family: Verdana, sans-serif; margin: 0px; padding: 0px;" /><span style="background-color: white; font-family: Verdana, sans-serif;">A zombie process is not the same as an orphan process. Orphan processes don't become zombie processes; instead, they are adopted by init (process ID 1), which waits on its children. </span><br style="font-family: Verdana, sans-serif; margin: 0px; padding: 0px;" /><br style="font-family: Verdana, sans-serif; margin: 0px; padding: 0px;" /><span style="background-color: white; font-family: Verdana, sans-serif;">The term zombie process derives from the common definition of zombie an undead person. </span><br style="font-family: Verdana, sans-serif; margin: 0px; padding: 0px;" /><br style="font-family: Verdana, sans-serif; margin: 0px; padding: 0px;" /><span style="background-color: white; font-family: Verdana, sans-serif;">Zombies can be identified in the output from the Unix PS command by the presence of a "Z" in the STAT column. Zombies that exist for more than a short period of time typically indicate a bug in the parent program. As with other leaks, the presence of a few zombies isn't worrisome in itself, but may indicate a problem that would grow serious under heavier loads. </span><br style="font-family: Verdana, sans-serif; margin: 0px; padding: 0px;" /><br style="font-family: Verdana, sans-serif; margin: 0px; padding: 0px;" /><span style="background-color: white; font-family: Verdana, sans-serif;">To remove zombies from a system, the SIGCHLD signal can be sent to the parent manually, using the kill command. If the parent process still refuses to reap the zombie, the next step would be to remove the parent process. When a process loses its parent, init becomes its new parent. Init periodically executes the wait system call to reap any zombies with init as parent. </span><br style="font-family: Verdana, sans-serif; margin: 0px; padding: 0px;" /><br style="font-family: Verdana, sans-serif; margin: 0px; padding: 0px;" /><span style="background-color: white; font-family: Verdana, sans-serif;"> </span><h2 style="font-family: Verdana, sans-serif; margin: 0px 0px 10px; padding: 0px;">
<a class="h2heading h2" href="" name="Orphan" style="margin: 0px; padding: 0px;"><span style="font-size: small;">Orphan Process</span></a></h2>
<span style="background-color: white; font-family: Verdana, sans-serif;">An orphan process is a computer process whose parent process has finished or terminated. </span><br style="font-family: Verdana, sans-serif; margin: 0px; padding: 0px;" /><br style="font-family: Verdana, sans-serif; margin: 0px; padding: 0px;" /><span style="background-color: white; font-family: Verdana, sans-serif;">A process can become orphaned during remote invocation when the client process crashes after making a request of the server. </span><br style="font-family: Verdana, sans-serif; margin: 0px; padding: 0px;" /><br style="font-family: Verdana, sans-serif; margin: 0px; padding: 0px;" /><span style="background-color: white; font-family: Verdana, sans-serif;">Orphans waste server resources and can potentially leave a server in trouble. However there are several solutions to the orphan process problem: </span><br />
<span style="font-family: Verdana, sans-serif;">1. Extermination is the most commonly used technique; in this case the orphan process is killed.</span><br />
<span style="font-family: Verdana, sans-serif;">2. Reincarnation is a technique in which machines periodically try to locate the parents of any remote computations; at which point orphaned processes are killed.</span><br />
<span style="font-family: Verdana, sans-serif;">3. Expiration is a technique where each process is allotted a certain amount of time to finish before being killed. If need be a process may "ask" for more time to finish before the allotted time expires.</span><span style="font-family: Verdana, sans-serif;"><br /></span><br style="font-family: Verdana, sans-serif; margin: 0px; padding: 0px;" /><span style="background-color: white; font-family: Verdana, sans-serif;">A process can also be </span><i style="font-family: Verdana, sans-serif; margin: 0px; padding: 0px;">orphaned</i><span style="background-color: white; font-family: Verdana, sans-serif;"> running on the same machine as its parent process. In a UNIX-like operating system any orphaned process will be immediately adopted by the special "init" system process. This operation is called re-parenting and occurs automatically. Even though technically the process has the "init" process as its parent, it is still called an orphan process since the process which originally created it no longer exists.</span><span style="font-family: Verdana, sans-serif; margin: 0px; padding: 0px;"><br style="margin: 0px; padding: 0px;" /></span></div>Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com0tag:blogger.com,1999:blog-4224221485098744558.post-60933363044737537842012-06-04T09:58:00.000+05:302012-06-04T09:58:23.334+05:30Linux Directory Structure (File System Structure)<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<h2 style="text-align: left;">
<span style="background-color: white; font-family: Arial, tahoma, Verdana, Arial, sans-serif; font-size: 14px; line-height: 23px; text-align: left;">The following list provides more detailed information and gives some examples which files and subdirectories can be found in the directories:</span></h2>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOPHFpzg5JwfiVvPhFQzhixnDON0yIWjGMFyXIcpCzSRUZ-tGW9XjvjtyDyff1uFPg9nhEKVvZoE42dsvzLBCIkuQtOtdsIRzSWXJwsgyBv0jO0pksKp0B-aGn52Hbv-BClOWm1HkykL9j/s1600/filesystem-structure.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOPHFpzg5JwfiVvPhFQzhixnDON0yIWjGMFyXIcpCzSRUZ-tGW9XjvjtyDyff1uFPg9nhEKVvZoE42dsvzLBCIkuQtOtdsIRzSWXJwsgyBv0jO0pksKp0B-aGn52Hbv-BClOWm1HkykL9j/s640/filesystem-structure.png" width="436" /></a></div>
<h3 style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.286em; font-weight: normal; line-height: 22px; margin: 1.833em 0px 0.611em; padding: 0px; text-align: -webkit-auto;">
<br /></h3>
<h3 style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.286em; font-weight: normal; line-height: 22px; margin: 1.833em 0px 0.611em; padding: 0px; text-align: -webkit-auto;">
<br /></h3>
<h3 style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.286em; font-weight: normal; line-height: 22px; margin: 1.833em 0px 0.611em; padding: 0px; text-align: -webkit-auto;">
1. / – Root</h3>
<ul style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; list-style: square; margin: 0px 0px 1.571em 1.571em; padding: 0px; text-align: -webkit-auto;">
<li style="margin: 0px; padding: 0px;">Every single file and directory starts from the root directory.</li>
<li style="margin: 0px; padding: 0px;">Only root user has write privilege under this directory.</li>
<li style="margin: 0px; padding: 0px;">Please note that /root is root user’s home directory, which is not same as /.</li>
</ul>
<h3 style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.286em; font-weight: normal; line-height: 22px; margin: 1.833em 0px 0.611em; padding: 0px; text-align: -webkit-auto;">
2. /bin – User Binaries</h3>
<ul style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; list-style: square; margin: 0px 0px 1.571em 1.571em; padding: 0px; text-align: -webkit-auto;">
<li style="margin: 0px; padding: 0px;">Contains binary executables.</li>
<li style="margin: 0px; padding: 0px;">Common linux commands you need to use in single-user modes are located under this directory.</li>
<li style="margin: 0px; padding: 0px;">Commands used by all the users of the system are located here.</li>
<li style="margin: 0px; padding: 0px;">For example: ps, ls, ping, grep, cp.</li>
</ul>
<h3 style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.286em; font-weight: normal; line-height: 22px; margin: 1.833em 0px 0.611em; padding: 0px; text-align: -webkit-auto;">
3. /sbin – System Binaries</h3>
<ul style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; list-style: square; margin: 0px 0px 1.571em 1.571em; padding: 0px; text-align: -webkit-auto;">
<li style="margin: 0px; padding: 0px;">Just like /bin, /sbin also contains binary executables.</li>
<li style="margin: 0px; padding: 0px;">But, the linux commands located under this directory are used typically by system aministrator, for system maintenance purpose.</li>
<li style="margin: 0px; padding: 0px;">For example: iptables, reboot, fdisk, ifconfig, swapon</li>
</ul>
<h3 style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.286em; font-weight: normal; line-height: 22px; margin: 1.833em 0px 0.611em; padding: 0px; text-align: -webkit-auto;">
4. /etc – Configuration Files</h3>
<ul style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; list-style: square; margin: 0px 0px 1.571em 1.571em; padding: 0px; text-align: -webkit-auto;">
<li style="margin: 0px; padding: 0px;">Contains configuration files required by all programs.</li>
<li style="margin: 0px; padding: 0px;">This also contains startup and shutdown shell scripts used to start/stop individual programs.</li>
<li style="margin: 0px; padding: 0px;">For example: /etc/resolv.conf, /etc/logrotate.conf</li>
</ul>
<h3 style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.286em; font-weight: normal; line-height: 22px; margin: 1.833em 0px 0.611em; padding: 0px; text-align: -webkit-auto;">
5. /dev – Device Files</h3>
<ul style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; list-style: square; margin: 0px 0px 1.571em 1.571em; padding: 0px; text-align: -webkit-auto;">
<li style="margin: 0px; padding: 0px;">Contains device files.</li>
<li style="margin: 0px; padding: 0px;">These include terminal devices, usb, or any device attached to the system.</li>
<li style="margin: 0px; padding: 0px;">For example: /dev/tty1, /dev/usbmon0</li>
</ul>
<h3 style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.286em; font-weight: normal; line-height: 22px; margin: 1.833em 0px 0.611em; padding: 0px; text-align: -webkit-auto;">
6. /proc – Process Information</h3>
<ul style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; list-style: square; margin: 0px 0px 1.571em 1.571em; padding: 0px; text-align: -webkit-auto;">
<li style="margin: 0px; padding: 0px;">Contains information about system process.</li>
<li style="margin: 0px; padding: 0px;">This is a pseudo filesystem contains information about running process. For example: /proc/{pid} directory contains information about the process with that particular pid.</li>
<li style="margin: 0px; padding: 0px;">This is a virtual filesystem with text information about system resources. For example: /proc/uptime</li>
</ul>
<h3 style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.286em; font-weight: normal; line-height: 22px; margin: 1.833em 0px 0.611em; padding: 0px; text-align: -webkit-auto;">
7. /var – Variable Files</h3>
<ul style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; list-style: square; margin: 0px 0px 1.571em 1.571em; padding: 0px; text-align: -webkit-auto;">
<li style="margin: 0px; padding: 0px;">var stands for variable files.</li>
<li style="margin: 0px; padding: 0px;">Content of the files that are expected to grow can be found under this directory.</li>
<li style="margin: 0px; padding: 0px;">This includes — system log files (/var/log); packages and database files (/var/lib); emails (/var/mail); print queues (/var/spool); lock files (/var/lock); temp files needed across reboots (/var/tmp);</li>
</ul>
<h3 style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.286em; font-weight: normal; line-height: 22px; margin: 1.833em 0px 0.611em; padding: 0px; text-align: -webkit-auto;">
8. /tmp – Temporary Files</h3>
<ul style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; list-style: square; margin: 0px 0px 1.571em 1.571em; padding: 0px; text-align: -webkit-auto;">
<li style="margin: 0px; padding: 0px;">Directory that contains temporary files created by system and users.</li>
<li style="margin: 0px; padding: 0px;">Files under this directory are deleted when system is rebooted.</li>
</ul>
<h3 style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.286em; font-weight: normal; line-height: 22px; margin: 1.833em 0px 0.611em; padding: 0px; text-align: -webkit-auto;">
9. /usr – User Programs</h3>
<ul style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; list-style: square; margin: 0px 0px 1.571em 1.571em; padding: 0px; text-align: -webkit-auto;">
<li style="margin: 0px; padding: 0px;">Contains binaries, libraries, documentation, and source-code for second level programs.</li>
<li style="margin: 0px; padding: 0px;">/usr/bin contains binary files for user programs. If you can’t find a user binary under /bin, look under /usr/bin. For example: at, awk, cc, less, scp</li>
<li style="margin: 0px; padding: 0px;">/usr/sbin contains binary files for system administrators. If you can’t find a system binary under /sbin, look under /usr/sbin. For example: atd, cron, sshd, useradd, userdel</li>
<li style="margin: 0px; padding: 0px;">/usr/lib contains libraries for /usr/bin and /usr/sbin</li>
<li style="margin: 0px; padding: 0px;">/usr/local contains users programs that you install from source. For example, when you install apache from source, it goes under /usr/local/apache2</li>
</ul>
<h3 style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.286em; font-weight: normal; line-height: 22px; margin: 1.833em 0px 0.611em; padding: 0px; text-align: -webkit-auto;">
10. /home – Home Directories</h3>
<ul style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; list-style: square; margin: 0px 0px 1.571em 1.571em; padding: 0px; text-align: -webkit-auto;">
<li style="margin: 0px; padding: 0px;">Home directories for all users to store their personal files.</li>
<li style="margin: 0px; padding: 0px;">For example: /home/john, /home/nikita</li>
</ul>
<h3 style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.286em; font-weight: normal; line-height: 22px; margin: 1.833em 0px 0.611em; padding: 0px; text-align: -webkit-auto;">
11. /boot – Boot Loader Files</h3>
<ul style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; list-style: square; margin: 0px 0px 1.571em 1.571em; padding: 0px; text-align: -webkit-auto;">
<li style="margin: 0px; padding: 0px;">Contains boot loader related files.</li>
<li style="margin: 0px; padding: 0px;">Kernel initrd, vmlinux, grub files are located under /boot</li>
<li style="margin: 0px; padding: 0px;">For example: initrd.img-2.6.32-24-generic, vmlinuz-2.6.32-24-generic</li>
</ul>
<h3 style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.286em; font-weight: normal; line-height: 22px; margin: 1.833em 0px 0.611em; padding: 0px; text-align: -webkit-auto;">
12. /lib – System Libraries</h3>
<ul style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; list-style: square; margin: 0px 0px 1.571em 1.571em; padding: 0px; text-align: -webkit-auto;">
<li style="margin: 0px; padding: 0px;">Contains library files that supports the binaries located under /bin and /sbin</li>
<li style="margin: 0px; padding: 0px;">Library filenames are either ld* or lib*.so.*</li>
<li style="margin: 0px; padding: 0px;">For example: ld-2.11.1.so, libncurses.so.5.7</li>
</ul>
<h3 style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.286em; font-weight: normal; line-height: 22px; margin: 1.833em 0px 0.611em; padding: 0px; text-align: -webkit-auto;">
13. /opt – Optional add-on Applications</h3>
<ul style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; list-style: square; margin: 0px 0px 1.571em 1.571em; padding: 0px; text-align: -webkit-auto;">
<li style="margin: 0px; padding: 0px;">opt stands for optional.</li>
<li style="margin: 0px; padding: 0px;">Contains add-on applications from individual vendors.</li>
<li style="margin: 0px; padding: 0px;">add-on applications should be installed under either /opt/ or /opt/ sub-directory.</li>
</ul>
<h3 style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.286em; font-weight: normal; line-height: 22px; margin: 1.833em 0px 0.611em; padding: 0px; text-align: -webkit-auto;">
14. /mnt – Mount Directory</h3>
<ul style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; list-style: square; margin: 0px 0px 1.571em 1.571em; padding: 0px; text-align: -webkit-auto;">
<li style="margin: 0px; padding: 0px;">Temporary mount directory where sysadmins can mount filesystems.</li>
</ul>
<h3 style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.286em; font-weight: normal; line-height: 22px; margin: 1.833em 0px 0.611em; padding: 0px; text-align: -webkit-auto;">
15. /media – Removable Media Devices</h3>
<ul style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; list-style: square; margin: 0px 0px 1.571em 1.571em; padding: 0px; text-align: -webkit-auto;">
<li style="margin: 0px; padding: 0px;">Temporary mount directory for removable devices.</li>
<li style="margin: 0px; padding: 0px;">For examples, /media/cdrom for CD-ROM; /media/floppy for floppy drives; /media/cdrecorder for CD writer</li>
</ul>
<h3 style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.286em; font-weight: normal; line-height: 22px; margin: 1.833em 0px 0.611em; padding: 0px; text-align: -webkit-auto;">
16. /srv – Service Data</h3>
<ul style="background-color: white; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; list-style: square; margin: 0px 0px 1.571em 1.571em; padding: 0px; text-align: -webkit-auto;">
<li style="margin: 0px; padding: 0px;">srv stands for service.</li>
<li style="margin: 0px; padding: 0px;">Contains server specific services related data.</li>
<li style="margin: 0px; padding: 0px;">For example, /srv/cvs contains CVS related data.</li>
</ul>
</div>Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com0tag:blogger.com,1999:blog-4224221485098744558.post-43293402533164850672012-06-04T09:28:00.000+05:302012-06-04T09:28:09.212+05:30Risks of using open source software<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<h1 style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 16px; margin: 0px 0px 8px; text-align: -webkit-auto;">
<br /></h1>
<br />
<span style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 22px; text-align: -webkit-auto;">Today's software development is geared more towards building upon previous work and less about reinventing content from scratch. Resourceful software development organisations and developers use a combination of previously created code, commercial software, </span><span class="maintext" style="margin: 0px;">open source software</span><span style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 22px; text-align: -webkit-auto;">, and their own creative content to produce the desired software product or functionality. Outsourced code can also be used, which in itself can contain any of the above combination of software.</span><br />
<div style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 22px; margin-bottom: 15px; margin-top: 3px; text-align: -webkit-auto;">
</div>
<div style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 22px; margin-bottom: 15px; margin-top: 3px; text-align: -webkit-auto;">
There are many good reasons for using off-the-shelf and especially open source software, with the greatest being its ability to speed up development and drive down costs without sacrificing quality. Almost all software groups knowingly, and in many cases unknowingly, use open source software to their advantage. Code reuse is possibly the biggest accelerator of innovation, as long as open source software is adopted and managed in a controlled fashion.</div>
<div style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 22px; margin-bottom: 15px; margin-top: 3px; text-align: -webkit-auto;">
In today's world of open-sourced, out-sourced, easily-searched and easily-copied software it is difficult for companies to know what is in their code. Any time a product containing software changes hands there is a need to understand its composition, pedigree, ownership, and any open source licences or obligations that restrict the rules around its use by new owners.</div>
<div style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 22px; margin-bottom: 15px; margin-top: 3px; text-align: -webkit-auto;">
Given developers' focus on the technical aspects of their work and emphasis on innovation, obligations associated with use of <span class="maintext" style="margin: 0px;">third party components</span> can be easily compromised. Ideally, companies track open source and third party code throughout the development lifecycle. If that is not the case then, at the very least, they should know what is in their code before engaging in a transaction that includes a software component.</div>
<div style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 22px; margin-bottom: 15px; margin-top: 3px; text-align: -webkit-auto;">
Examples of transactions involving software are: a launch of a product into the market, merger & acquisition (M&A) of companies with <span class="maintext" style="margin: 0px;">software development operations</span>, and technology transfer between organisations whether they are commercial, academic or public. Any company that produces software as part of a software supply chain must be aware of what is in their code base.</div>
<div style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 22px; margin-bottom: 15px; margin-top: 3px; text-align: -webkit-auto;">
<b style="margin: 0px;">Impact of Code Uncertainties</b></div>
<div style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 22px; margin-bottom: 15px; margin-top: 3px; text-align: -webkit-auto;">
Any uncertainty around software ownership or licence compliance can deter downstream users, reduce ability to create partnerships, and create litigation risk to the company and their customers. For smaller companies, Intellectual Property (IP) uncertainties can also delay or otherwise threaten closures in funding deals, affect product and company value, and negatively impact M&A activities.</div>
<div style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 22px; margin-bottom: 15px; margin-top: 3px; text-align: -webkit-auto;">
IP uncertainties can affect the competitiveness of small technology companies due to indemnity demands from their clients. Technology companies need to understand the obligations associated with the software that they are acquiring. Any uncertainties around third party content in code can also stretch sales cycles. Lack of internal resources allocated to identification, tracking and maintaining open source and other third party code in a project impacts smaller companies even more.</div>
<div style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 22px; margin-bottom: 15px; margin-top: 3px; text-align: -webkit-auto;">
Along with licencing issues and IP uncertainties, organisations that use open source also need to be aware of security vulnerabilities. A number of public databases, such as the US National Vulnerability Database (NVD) or Carnegie Mellon University's Computer Emergency Response Team (CERT) database, list known vulnerabilities associated with a large number of software packages. Without an accurate knowledge of what exists in the code base it is not possible to consult these databases. Aspects such as known deficiencies, vulnerabilities, known security risks, and code pedigree all assume the existence of software bill of materials. In a number of jurisdictions, another important aspect to consider before a software transaction takes place is whether the code includes encryption content or other content subject to export control – this is important to companies that do business internationally.</div>
<div style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 22px; margin-bottom: 15px; margin-top: 3px; text-align: -webkit-auto;">
<b style="margin: 0px;">Solutions</b></div>
<div style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 22px; margin-bottom: 15px; margin-top: 3px; text-align: -webkit-auto;">
The benefits of open source software usage can be realised and the risks can be managed at the same time. Ideally, a company using open source software should have a process in place to ensure that open source software is properly adopted and managed throughout the development cycle. Having such a process in place allows organisations to detect any licencing or IP uncertainties at the earliest possible stage during development which reduces the time, effort, and cost associated correcting the problem later down the road. </div>
<div>
<br /></div>
</div>Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com0tag:blogger.com,1999:blog-4224221485098744558.post-28176191152155659202012-05-30T10:48:00.000+05:302012-05-30T10:48:36.156+05:30Process vs Threads<div dir="ltr" style="text-align: left;" trbidi="on">
<blockquote cite="http://www.devx.com/Intel/Article/29815">
Both threads and processes are methods of parallelizing an application.
However, processes are <b>independent execution units </b>that contain their
own state information, use their own address spaces, and only interact
with each other via interprocess communication mechanisms (generally
managed by the operating system). Applications are typically divided
into processes during the design phase, and a master process explicitly
spawns sub-processes when it makes sense to logically separate
significant application functionality. Processes, in other words, are an
architectural construct.
</blockquote>
<br />
<blockquote cite="http://www.devx.com/Intel/Article/29815">
By contrast, a thread is a coding construct that doesn't affect the
architecture of an application. A single process might contains multiple
threads; all threads within a process share the <b>same state and same
memory space</b>, and can communicate with each other directly, because they
share the same variables.
</blockquote>
<br />
<blockquote cite="http://www.devx.com/Intel/Article/29815">
Threads typically are spawned for a short-term benefit that is usually
visualized as a serial task, but which doesn't have to be performed in a
linear manner (such as performing a complex mathematical computation
using parallelism, or initializing a large matrix), and then are
absorbed when no longer required. The scope of a thread is within a
specific code module—which is why we can bolt-on threading without
affecting the broader application.
</blockquote>
</div>Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com0tag:blogger.com,1999:blog-4224221485098744558.post-49343101091322669262012-05-30T10:22:00.000+05:302012-05-30T10:22:02.299+05:30The Kernel Source Tree<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
The kernel source tree is divided into a number of directories, most of which contain many more subdirectories.The directories in the root of the source tree, along with their descriptions.<br />
<br />
<br />
<br />
<br />
<br />
<h3 style="text-align: left;">
<b>Directory Description</b></h3>
<br />arch Architecture-specific source<br />block Block I/O layer<br />crypto Crypto API<br />Documentation Kernel source documentation<br />drivers Device drivers<br />firmware Device firmware needed to use <br />
certain drivers<br />fs The VFS and the individual filesystems<br />include Kernel headers<br />init Kernel boot and initialization<br />ipc Interprocess communication code<br />kernel Core subsystems, such as the scheduler<br />lib Helper routines<br />mm Memory management subsystem and<br />
the VM<br />net Networking subsystem<br />samples Sample, demonstrative code<br />scripts Scripts used to build the kernel<br />security Linux Security Module<br />sound Sound subsystem<br />usr Early user-space code (called initramfs)<br />tools Tools helpful for developing Linux<br />virt Virtualization infrastructure<br /><br /><br /><br /></div>Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com0tag:blogger.com,1999:blog-4224221485098744558.post-32889252936796369762012-05-29T10:27:00.000+05:302012-05-29T10:27:38.238+05:30Linux Daemon and services<div dir="ltr" style="text-align: left;" trbidi="on">
<table><tbody>
<tr><td width="10%"><br /></td><td width="80%"><div style="color: #38761d;">
<br /></div>
<b><span style="color: #38761d;">A daemon should be distinguished from a </span><i style="color: #38761d;">demon</i><span style="color: #38761d;">, which is an evil spirit in some religions. </span>
</b><br />
<br />
<br />
A <i>daemon</i> is a type of program on Unix-like operating systems
that runs unobtrusively in the background, rather than under the direct
control of a user, waiting to be activated by the occurance of a
specific event or condition.<br />
<br />
Unix-like systems typically run numerous daemons, mainly to accommodate
requests for services from other computers on a network, but also to
respond to other programs and to hardware activity. Examples of actions
or conditions that can trigger daemons into activity are a specific time
or date, passage of a specified time interval, a file landing in a
particular directory, receipt of an e-mail or a Web request made through
a particular communication line. It is not necessary that the
perpetrator of the action or condition be aware that a daemon is <i>listening</i>, although programs frequently will perform an action only because they are aware that they will implicitly arouse a daemon.
<br />
Daemons are usually instantiated as <i>processes</i>. A process is an <i>executing</i> (i.e., running) instance of a program. Processes are managed by the <i>kernel</i> (i.e., the core of the operating system), which assigns each a unique <i>process identification number</i> (PID).
<br />
There are three basic types of processes in Linux: interactive, batch and daemon. Interactive processes are run interactively by a user at the <i>command line</i>
(i.e., all-text mode). Batch processes are submitted from a queue of
processes and are not associated with the command line; they are well
suited for performing recurring tasks when system usage is otherwise
low.
<br />
Daemons are recognized by the system as any processes whose <i>parent process</i> has a PID of one, which always represents the process <i>init</i>. init is always the first process that is started when a Linux computer is <i>booted up</i> (i.e., started), and it remains on the system until the computer is turned off. init <i>adopts</i> any process whose <i>parent</i> process <i>dies</i> (i.e., terminates) without waiting for the <i>child</i> process's status. Thus, the common method for launching a daemon involves <i>forking</i>
(i.e., dividing) once or twice, and making the parent (and grandparent)
processes die while the child (or grandchild) process begins performing
its normal function.
<br />
Some daemons are launched via <i>System V init scripts</i>, which are <i>scripts</i>
(i.e., short programs) that are run automatically when the system is
booting up. They may either survive for the duration of the session or
be regenerated at intervals.
<br />
Many daemons are now started only as required and by a single daemon, <i>xinetd</i> (which has replaced <i>inetd</i> in newer systems), rather than running continuously. xinetd, which is referred to as a <i>TCP/IP super server</i>, itself is started at boot time, and it listens to the <i>ports</i> assigned to the processes listed in the <i>/etc/inetd.conf</i> or in <i>/etc/xinetd.conf</i> configuration file. Examples of daemons that it starts include <i>crond</i> (which runs scheduled tasks), <i>ftpd</i> (file transfer), <i>lpd</i> (laser printing), <i>rlogind</i> (remote login), <i>rshd</i> (remote command execution) and <i>telnetd</i> (telnet).
<br />
In addition to being launched by the operating system and by application
programs, some daemons can also be started manually. Examples of
commands that launch daemons include <i>binlogd</i> (which logs binary events to specified files), <i>mysqld</i> (the MySQL databse server) and <i>apache</i> (the Apache web server).
<br />
In many Unix-like operating systems, including Linux, each daemon has a single <i>script</i>
(i.e., short program) with which it can be terminated, restarted or
have its status checked. The handling of these scripts is based on <i>runlevels</i>.
A runlevel is a configuration or operating state of the system that
only allows certain selected processes to exist. Booting into a
different runlevel can help solve certain problems, including repairing
system errors.
<br />
The term <i>daemon</i> is derived from the daemons of Greek mythology,
which were supernatural beings that ranked between gods and mortals and
which possessed special knowledge and power<sup>1</sup>.
For example, Socrates claimed to have a daemon that gave him warnings
and advice but never coerced him into following it. He also claimed that
his daemon exhibited greater accuracy than any of the forms of
divination practiced at the time.
<br />
The word <i>daemon</i> was first used in a computer context at the
pioneering Project MAC (which later became the MIT Laboratory for
Computer Science) using the IBM 7094 in 1963. This usage was inspired by
Maxwell's daemon of physics and thermodynamics, which was an imaginary
agent that helped sort molecules of different speeds and worked
tirelessly in the background. The term was then used to describe
background processes which worked tirelessly to perform system chores.
The first computer daemon was a program that automatically made tape
backups. After the term was adopted for computer use, it was
rationalized as an acronym for <i>Disk And Execution MONitor</i>.
<br />
On the Microsoft Windows operating systems, programs called <i>services</i> perform the functions of daemons, although the term <i>daemon</i> is now sometimes being used with regard to those systems as well.<br />
<br />
<br />
<table border="1" cellpadding="2" cellspacing="0"><tbody>
<tr><td style="font-weight: bold; vertical-align: top;">acpid<br />
</td>
<td style="vertical-align: top;">This a completely flexible,
totally extensible daemon for delivering
ACPI events. It listens on a file (<i>/proc/acpi/event</i>) and when an
event occurs, executes programs to handle the event.<br />
ACPI stands for: Advanced Configuration and Power Interface.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">aep1000<br />
</td>
<td style="vertical-align: top;">For AEP 1000 coprocessors. It's
used for hardware cryptographic acceleration under Linux.</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">anacron<br />
</td>
<td style="vertical-align: top;"> Anacron is a periodic command
scheduler. It executes commands at
intervals specified in days. Unlike cron, it does not assume that the
system is running continuously.<br />
Every time Anacron is run, it reads a configuration file that
specifies the jobs Anacron controls, and their periods in days. If a
job wasn't executed in the last n days, where n is the period of that
job, Anacron executes it. Anacron then records the date in a special
timestamp file that it keeps for each job, so it can know when to run
it again<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">apmd<br />
</td>
<td style="vertical-align: top;">The apmd package is a set of
user-level programs to control the Advanced
Power Management system found in all modern laptop computers and most
modern
desktops.
apmd talks to the Linux kernel APM layer, which does all the
hardware-dependent stuff.</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">atd<br />
</td>
<td style="vertical-align: top;">atd runs jobs queued by at.</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">autofs<br />
</td>
<td style="vertical-align: top;">Auto-autofs detects Disks,
Partitions, CD-ROMs, Floppies etc. and sets up an automount
configuration.<br />
So it provides an easy access to the hardware.<br />
Auto-autofs is a Perl script that searches
the hardware for block devices using the <i>/proc</i> directory.
It finds partitions on harddisks via fdisk and tries to detect the
filesystems. <br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">bcm5820<br />
</td>
<td style="vertical-align: top;">Hardware cryptographic
accelerator support for Broadcom BCM5820 eCommerce Processor.</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">chargen<br />
</td>
<td style="vertical-align: top;">Character Generator Protocol.<br />
A useful debugging and measurement tool is a character
generator service. A character generator service simply sends data
without regard to the input. Listens on port 19 TCP/UDP.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">chargen-udp<br />
</td>
<td style="vertical-align: top;">See chargen.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">crond<br />
</td>
<td style="vertical-align: top;">Daemon to execute scheduled
commands.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">cups<br />
</td>
<td style="vertical-align: top;">The Common UNIX Printing System
("CUPS") is a cross-platform printing solution for all UNIX
environments. It is based on the "Internet Printing Protocol" and
provides complete printing services to most PostScript and raster
printers. </td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">cups-lpd<br />
</td>
<td style="vertical-align: top;">This is the CUPS Line
Printer Daemon ("LPD") mini-server that supports legacy client systems
that use the LPD protocol. </td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">daytime </td>
<td style="vertical-align: top;">The Daytime Protocol (Internet
RFC 867) is a simple protocol
that allows clients to retrieve the current date and time from a remote
server. While useful at a bsic level, the Daytime protocol is most
often used
for debugging purposes rather than actually acquire the current date
and time. The daytime protocol is available on TCP port 13. </td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">daytime-udp<br />
</td>
<td style="vertical-align: top;">See daytime.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">echo<br />
</td>
<td style="vertical-align: top;">Service for testing, everything
you send to port 7 (echo) would be sent back to you.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">echo-udp<br />
</td>
<td style="vertical-align: top;">see echo<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">gpm<br />
</td>
<td style="vertical-align: top;">General Purpose Mouse Daemon.
Necessary only if
you want to use your mouse on the console (not xterms). </td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">httpd<br />
</td>
<td style="vertical-align: top;">The apache web server.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">iptables<br />
</td>
<td style="vertical-align: top;">firewall<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">irda<br />
</td>
<td style="vertical-align: top;">(Infrared Data Association) is
an industry standard for infrared wireless communication.</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">irqbalance<br />
</td>
<td style="vertical-align: top;">Daemon to balance irq's across
multiple CPUs. Only useful on SMP systems (more than one processor)<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">isdn<br />
</td>
<td style="vertical-align: top;">ISDN (Integrated Services
Digital Network). Use only with ISDN network interfaces.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">ktalk<br />
</td>
<td style="vertical-align: top;">A graphical talk client for KDE.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">kudzu<br />
</td>
<td style="vertical-align: top;">Detects and configures new
and/or changed hardware on a system.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">lisa<br />
</td>
<td style="vertical-align: top;"> LISa is a small daemon which is
intended to run on end user systems.
It provides something like a "network neighborhood", but only relying
on the TCP/IP protocol stack, no smb or whatever.<br />
The information about the hosts in your "neighborhood" is provided via
TCP port 7741.<br />
To use it: from a client computer, open konqueror and type
lan://targetIP<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">messagebus<br />
</td>
<td style="vertical-align: top;">D-BUS is first a library
that provides one-to-one communication between any two
applications; <i>dbus-daemon-1</i> is an application that
uses this library to implement a message bus daemon.
Multiple programs connect to the message bus daemon and can
exchange messages with one another.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">microcode_ctl<br />
</td>
<td style="vertical-align: top;">It decodes and sends new
microcode to the kernel driver to be uploaded to
Intel IA32 processors. (Pentium Pro, PII, PIII, Pentium 4, Celeron,
Xeon etc -
all P6 and above, which does NOT include pentium classics) <br />
It signals the kernel driver to release any buffers it may hold.<br />
The microcode update is volatile and needs to be uploaded on each
system
boot i.e. it doesn't reflash your cpu permanently, reboot and it
reverts
back to the old microcode.<br />
This driver is designed for Intel IA32 microprocessors only, it will
not work
with AMD or any other non-Intel processors as they don't support
microcode
updates or they support it in a manner different from Intel's specs.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">mysqld<br />
</td>
<td style="vertical-align: top;">MySQL database server.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">named<br />
</td>
<td style="vertical-align: top;">DNS server. Bind.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">netfs<br />
</td>
<td style="vertical-align: top;">Network Filesystem Mounter.
Needed for mounting NFS, SMB and NCP shares on boot. </td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">network<br />
</td>
<td style="vertical-align: top;">Activates all network interfaces
at boot time. </td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">nfslock<br />
</td>
<td style="vertical-align: top;">To help manage file access
conflicts and
protect NFS sessions during failures, NFS offers a file and record
locking service called the <span class="FIRSTTERM">network lock manager</span>.
The network lock manager is a separate service NFS makes available to
user applications. To use the locking service, applications must make
calls to standard lock routines. </td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">ntpd<br />
</td>
<td style="vertical-align: top;">The <tt>ntpd</tt> sets and
maintains the system time of day in synchronism with Internet standard
time servers. It is a complete implementation of the Network Time
Protocol (NTP) version 4. Allows other computers to synchronize system
time with your server.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">pcmcia<br />
</td>
<td style="vertical-align: top;">PCMCIA cards.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">portmap<br />
</td>
<td style="vertical-align: top;"> The <span class="COMMAND">portmap</span>
service is a dynamic port assignment daemon for RPC services such as
NIS and NFS. </td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">postgresql<br />
</td>
<td style="vertical-align: top;">PostgreSQL database server.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">random<br />
</td>
<td style="vertical-align: top;">Initialize kernel random number
generator </td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">rawdevices<br />
</td>
<td style="vertical-align: top;">Block devices. Links
hardware to devices that store data.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">rhnsd<br />
</td>
<td style="vertical-align: top;">Red Hat Network Service. Informs
you about official security and bug updates for your system.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">rsync<br />
</td>
<td style="vertical-align: top;">Its just like rpc with much more
features. Provides a very fast method for bringing
remote files into sync. </td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">saslauthd<br />
</td>
<td style="vertical-align: top;">SASL (Simple Authentication and
Security Layer) authentication server. Server to allow others identify
on this server.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">sendmail<br />
</td>
<td style="vertical-align: top;">Mail server, allows to send
emails using this machine as mail server.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">services<br />
</td>
<td style="vertical-align: top;">An internal xinetd services,
listing active services.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">sgi_fam<br />
</td>
<td style="vertical-align: top;">File Alteration Monitor,
provides an API that applications can use to be notified when specific
files or directories are changed. For example, consider a graphical
file manager, when the user removes a file thru the file manager, their
changes are visible immediately.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">smartd<br />
</td>
<td style="vertical-align: top;">Self Monitor Analysis and
Reporting Technology System. Monitor you hard disk for failures.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">smb<br />
</td>
<td style="vertical-align: top;">Samba, allows to share and
access MS windows network.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">snmpd<br />
</td>
<td style="vertical-align: top;">Simple Network Management
protocol. A standard protocol for non-windows networks.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">snmptrapd<br />
</td>
<td style="vertical-align: top;">This is an SNMP application that
recieves and logs SNMP TRAP and INFORM messages. Uses UDP port 162.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">squid<br />
</td>
<td style="vertical-align: top;">Web proxy cache. <br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">sshd<br />
</td>
<td style="vertical-align: top;">Secure Shell daemon, allows
secure and remote logging to this machine.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">syslog<br />
</td>
<td style="vertical-align: top;">Logs all system activities.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">time<br />
</td>
<td style="vertical-align: top;">Retrieve the date and time from
a
host or hosts on the network and set the local system time TCP version.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">time-udp<br />
</td>
<td style="vertical-align: top;">Retrieve the date and time from
a
host or hosts on the network and set the local system time UDP version.</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">tux<br />
</td>
<td style="vertical-align: top;"><span class="para">The TUX Web
Server is an HTTP daemon for Linux .
The TUX Web Server is different from other Web servers in that it runs
partially from within the Linux kernel as a module, or kernel
subsystem. Given sufficient networking cards, it enables direct
scatter-gather direct memory access (DMA) and hardware-based TCP/IP
checksums from the page cache (the Linux file data cache) directly to
the network, avoiding extra data copies.</span> </td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">vncserver<br />
</td>
<td style="vertical-align: top;">VNC stands for Virtual Network
Computing. It is remote
control software which allows you to view and interact with one
computer
(the "server") using a simple program (the "viewer") on another
computer anywhere on the Internet.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">vsftpd<br />
</td>
<td style="vertical-align: top;">Secure FTP daemon.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">winbind</td>
<td style="vertical-align: top;">
Winbind is an nss switch module to map Windows NT Domain
databases to Unix.<br />
In combination with Samba and pam_ntdom, a Unix box will be able to
integrate straight into a full Windows NT Domain environment, without
needing a Unix Account database.<br />
<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">xfs<br />
</td>
<td style="vertical-align: top;">The X font server (<code>xfs</code>)
provides a standard mechanism for
an X server to communicate with a font renderer, frequently running on
a remote machine. It usually runs on TCP port 7100.<br />
You need to be running <code>xfs</code> if you want a remote X
terminal to be able to use fonts from your system, or if you want to
use fonts that your X server doesn't understand (and the font server
does).<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">xinetd<br />
</td>
<td style="vertical-align: top;">Service wrapper. xinetd is a
replacement for inetd, the internet services daemon.<br />
xinetd - eXtended InterNET services daemon - provides a good security
against
intrusion and reduces the risks of Denial of Services (DoS)
attacks. Like the well known couple
(inetd+tcpd), it enables the configuration of the access
rights for a given
machine.<br />
</td>
</tr>
<tr>
<td style="font-weight: bold; vertical-align: top;">yum<br />
</td>
<td style="vertical-align: top;">yum is an automatic updater and
package installer/remover for rpm systems. <br />
It automatically computes dependencies and figures out what things
should occur to install packages. <br />
It makes it easier to maintain groups of machines without having to
manually update each one using rpm.<br /><br />
<a href="http://linux.duke.edu/projects/yum/"></a></td></tr>
</tbody></table>
</td></tr>
</tbody></table>
</div>Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com1tag:blogger.com,1999:blog-4224221485098744558.post-77110296249644064802012-05-28T13:14:00.002+05:302012-05-28T13:14:42.879+05:30How to: Compile Linux kernel 2.6<div dir="ltr" style="text-align: left;" trbidi="on">
Compiling custom kernel has its own advantages and disadvantages.
However, new Linux user / admin find it difficult to compile Linux
kernel. Compiling kernel needs to understand few things and then just
type couple of commands.<br />
<br />
<h2>
Step # 1 Get Latest Linux kernel code</h2>
Visit <a href="http://kernel.org/">http://kernel.org/</a>
and download the latest source code. File name would be
linux-x.y.z.tar.bz2, where x.y.z is actual version number. For example
file inux-2.6.25.tar.bz2 represents 2.6.25 kernel version. Use wget
command to download kernel source code:<br /> <code>$ cd /tmp<br /> $ wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-x.y.z.tar.bz2</code><br />
Note: Replace x.y.z with actual version number.<br />
<br />
<h2>
Step # 2 Extract tar (.tar.bz3) file</h2>
Type the following command:<br /> <code># tar -xjvf linux-2.6.25.tar.bz2 -C /usr/src<br /> # cd /usr/src</code><br />
<h2>
Step # 3 Configure kernel</h2>
Before
you configure kernel make sure you have development tools (gcc
compilers and related tools) are installed on your system. If gcc
compiler and tools are not installed then use apt-get command under
Debian Linux to install development tools.<br /> <code># apt-get install gcc </code><br />
Now you can start kernel configuration by typing any one of the command:<br />
<br />
<ul>
<li><b>$ make menuconfig</b> - Text based color menus, radiolists
& dialogs. This option also useful on remote server if you wanna
compile kernel remotely.</li>
<li><b>$ make xconfig</b> - X windows (Qt) based configuration tool, works best under KDE desktop</li>
<li><b>$ make gconfig</b> - X windows (Gtk) based configuration tool, works best under Gnome Dekstop.</li>
</ul>
For example make menuconfig command launches following screen:<br /> <code>$ make menuconfig</code><br />
You
have to select different options as per your need. Each configuration
option has HELP button associated with it so select help button to get
help.<br />
<h2>
Step # 4 Compile kernel</h2>
Start compiling to create a compressed kernel image, enter:<br /> <code>$ make</code><br /> Start compiling to kernel modules:<br /> <code>$ make modules </code><br />
Install kernel modules (become a root user, use su command):<br /> <code>$ su -<br /> # make modules_install<br /> </code><br />
<h2>
Step # 5 Install kernel</h2>
So far we have compiled kernel and installed kernel modules. It is time to install kernel itself.<br /> <code># make install </code><br />
It will install three files into /boot directory as well as modification to your kernel grub configuration file:<br />
<br />
<ul>
<li>System.map-2.6.25</li>
<li>config-2.6.25</li>
<li>vmlinuz-2.6.25</li>
</ul>
<h2>
Step # 6: Create an initrd image</h2>
Type the following command at a shell prompt:<br /> <code># cd /boot<br /> # mkinitrd -o initrd.img-2.6.25 2.6.25</code><br />
initrd
images contains device driver which needed to load rest of the
operating system later on. Not all computer requires initrd, but it is
safe to create one.<br />
<h2>
Step # 7 Modify Grub configuration file - /boot/grub/menu.lst</h2>
Open file using vi:<br /> <code># vi /boot/grub/menu.lst</code><br />
<pre>title Debian GNU/Linux, kernel 2.6.25 Default
root (hd0,0)
kernel /boot/vmlinuz root=/dev/hdb1 ro
initrd /boot/initrd.img-2.6.25
savedefault
boot</pre>
Remember to setup correct root=/dev/hdXX device. Save and
close the file. If you think editing and writing all lines by hand is
too much for you, try out update-grub command to update the lines for
each kernel in /boot/grub/menu.lst file. Just type the command:<br /> <code># update-grub</code><br /> Neat. Huh?<br />
<h2>
Step # 8 : Reboot computer and boot into your new kernel</h2>
Just issue reboot command:<br /> <code># reboot</code><br />
<br />
<br />
<code>........................................................................ </code><br />
<br />
</div>Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com0tag:blogger.com,1999:blog-4224221485098744558.post-15152026773489019722012-05-24T15:34:00.001+05:302012-05-24T15:34:40.430+05:30Linux kernel and classic Unix systems<div dir="ltr" style="text-align: left;" trbidi="on">
<h3 style="text-align: left;">
<b> Main differences exist between the Linux kernel and classic Unix systems:</b></h3>
<div style="text-align: left;">
</div>
<br />
1.Linux supports the dynamic loading of kernel modules.Although the Linux kernel is monolithic, it can dynamically load and unload kernel code on demand.<br />
<br />2.Linux has symmetrical multiprocessor (SMP) support.Although most commercial variants of Unix now support SMP, most traditional Unix implementations did not.<br /><br />
3.The Linux kernel is preemptive. Unlike traditional Unix variants, the Linux kernel can preempt a task even as it executes in the kernel. Of the other commercial Unix implementations, Solaris and IRIX have preemptive kernels, but most Unix kernels are not preemptive.<br /><br />
4. Linux takes an interesting approach to thread support: It does not differentiate between threads and normal processes.To the kernel, all processes are the same— some just happen to share resources.<br /><br />
5. Linux provides an object-oriented device model with device classes, hot-pluggable events, and a user-space device filesystem (sysfs).<br /><br />
6.Linux ignores some common Unix features that the kernel developers consider poorly designed, such as STREAMS, or standards that are impossible to cleanly implement.<br /><br />
7.Linux is free in every sense of the word.The feature set Linux implements is the result of the freedom of Linux’s open development model. If a feature is without merit or poorly thought out, Linux developers are under no obligation to implement it.To the contrary, Linux has adopted an elitist attitude toward changes: Modifications must solve a specific real-world problem, derive from a clean design, and have a solid implementation. Consequently, features of some other modern Unix variants that are more marketing bullet or one-off requests, such as pageable kernel memory, have received no consideration.<br />
<br />
<br /><b>Despite these differences, however, Linux remains an operating system with a strong Unix heritage.</b><br /></div>Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com0tag:blogger.com,1999:blog-4224221485098744558.post-37129097020301726702012-05-24T11:01:00.001+05:302012-05-24T11:01:11.977+05:30Kernel Role<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Kernel role can be split into following parts:- </b><br />
<br />
<br />
<b>Process management</b><br />The kernel is in charge of creating and destroying processes and handling their connection to the outside world (input and output). Communication among different processes (through signals, pipes, or interprocess communication primitives) is basic to the overall system functionality and is also handled by the kernel. In addition, the scheduler, which controls how processes share the CPU, is part of process management. More generally, the kernel’s process management activity implements the abstraction of several processes on top of a single CPU or a few of them.<br /><br />
<b>Memory management</b><br />The computer’s memory is a major resource, and the policy used to deal with it is a critical one for system performance. The kernel builds up a virtual addressing space for any and all processes on top of the limited available resources. The different parts of the kernel interact with the memory management subsystem through a set of function calls, ranging from the simple malloc/free pair to much more complex functionalities.<br /><br />
<b>Filesystems</b><br /> Unix is heavily based on the filesystem concept; almost everything in Unix can be treated as a file. The kernel builds a structured filesystem on top of unstructured hardware, and the resulting file abstraction is heavily used throughout the whole system. In addition, Linux supports multiple filesystem types, that is, different ways of organizing data on the physical medium. For example, disks may be formatted with the Linux-standard ext3 filesystem, the commonly used FAT filesystem or several others.<br />
<br />
<b>Device control</b><br />Almost every system operation eventually maps to a physical device. With the exception of the processor, memory, and a very few other entities, any and all device control operations are performed by code that is specific to the device being addressed. That code is called a device driver. The kernel must have embedded in it a device driver for every peripheral present on a system, from the hard drive to the keyboard and the tape drive. This aspect of the kernel’s functions is our primary interest in this book.<br /><br />
<b>Networking</b><br />Networking must be managed by the operating system, because most network operations are not specific to a process: incoming packets are asynchronous events. The packets must be collected, identified, and dispatched before a process takes care of them. The system is in charge of delivering data packets across program and network interfaces, and it must control the execution of programs according to their network activity. Additionally, all the routing and address resolution issues are implemented within the kernel.<br /></div>Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com0tag:blogger.com,1999:blog-4224221485098744558.post-28642284899858108222012-05-24T10:41:00.000+05:302012-05-24T10:41:05.175+05:30More About Sockets...... protocols and syntax...!!!!<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Socket Protocols</b><br /><br />
Where the underlying transport mechanism allows for more than one protocol to provide the requested socket type, you can select a specific protocol for a socket.<br />
<br />
<b>Creating a Socket</b><br />
<b> </b><br />The socket system call creates a socket and returns a descriptor that can be used for accessing the socket.<br />
<br />
#include <sys/types.h><br />#include <sys/socket.h><br />int socket(int domain, int type, int protocol);<br /><br />
The socket created is one end point of a communication channel. The domain parameter specifies the address family, the type parameter specifies the type of communication to be used with this socket, and protocol specifies the protocol to be employed.<br />
<br />Domains include the following:<br /><br />
AF_UNIX UNIX internal (file system sockets)<br />AF_INET ARPA Internet protocols (UNIX network sockets)<br />AF_ISO ISO standard protocols<br />AF_NS Xerox Network Systems protocols<br />AF_IPX Novell IPX protocol<br />AF_APPLETALK Appletalk DDS<br /><br />
The most common socket domains are AF_UNIX, which is used for local sockets implemented via the UNIX and Linux file systems, and AF_INET, which is used for UNIX network sockets. The AF_INET sockets may be used by programs communicating across a TCP/IP network including the Internet. The Windows Winsock interface also provides access to this socket domain.<br />The socket parameter type specifies the communication characteristics to be used for the new socket. Possible values include SOCK_STREAM and SOCK_DGRAM.<br />SOCK_STREAM is a sequenced, reliable, connection-based two-way byte stream. For an AF_INET domain socket, this is provided by default by a TCP connection that is established between the two end points of the stream socket when it’s connected. Data may be passed in both directions along the socket connection. The TCP protocols include facilities to fragment and reassemble long messages and to retransmit any parts that may be lost in the network.<br />SOCK_DGRAM is a datagram service. You can use this socket to send messages of a fixed (usually small) maximum size, but there’s no guarantee that the message will be delivered or that messages won’t be reordered in the network. For AF_INET sockets, this type of communication is provided by UDP datagrams.<br />
<br />
<br />
The protocol used for communication is usually determined by the socket type and domain. There is normally no choice. The protocol parameter is used where there is a choice. 0 selects the default protocol, which we’ll use in all our examples.<br />The socket system call returns a descriptor that is in many ways similar to a low-level file descriptor. When the socket has been connected to another end-point socket, you may use the read and write system calls with the descriptor to send and receive data on the socket. The close system call is used to end a socket connection.<br /><br />
<b>Socket Addresses</b><br /><br />
Each socket domain requires its own address format. For an AF_UNIX socket, the address is described by a structure, sockaddr_un, defined in the sys/un.h include file.<br />
<br /><b>struct sockaddr_un {<br />sa_family_t<br />sun_family;<br />char<br />sun_path[];<br />}</b>;<br />/* AF_UNIX */<br />/* pathname */<br /><br />
<br />
So that addresses of different types may be passed to the socket-handling system calls, each address format is described by a similar structure that begins with a field (in this case, sun_family) that specifies the address type (the socket domain). In the AF_UNIX domain, the address is specified by a filename in the sun_path field of the structure.<br />On current Linux systems, the type sa_family_t, defined by X/Open as being declared in sys/un.h, is taken to be a short. Also, the pathname specified in sun_path is limited in size (Linux specifies 108 characters; others may use a manifest constant such as UNIX_MAX_PATH). Because address structures<br />may vary in size, many socket calls require or provide as an output a length to be used for copying the particular address structure.<br />In the AF_INET domain, the address is specified using a structure called sockaddr_in, defined in netinet/in.h, which contains at least these members:<br /><br />
<b>struct sockaddr_in {<br />short int<br />unsigned short int<br />struct in_addr<br />};<br />sin_family;<br />sin_port;<br />sin_addr;</b><br />/* AF_INET */<br />/* Port number */<br />/* Internet address */<br /><br />
The IP address structure, in_addr, is defined as follows:<br /><br />
struct in_addr {<br />unsigned long int<br />};<br />s_addr;<br /><br />
The four bytes of an IP address constitute a single 32-bit value. An AF_INET socket is fully described by its domain, IP address, and port number. From an application’s point of view, all sockets act like file descriptors and are addressed by a unique integer value.<br />
<br />
<b>Naming a Socket</b><br />
<b> </b><br />To make a socket (as created by a call to socket) available for use by other processes, a server program needs to give the socket a name. Thus, AF_UNIX sockets are associated with a file system pathname, as you saw in the server1 example. AF_INET sockets are associated with an IP port number.<br /><br />
#include <sys/socket.h><br />int bind(int socket, const struct sockaddr *address, size_t address_len);<br /><br />
The bind system call assigns the address specified in the parameter, address, to the unnamed socket associated with the file descriptor socket. The length of the address structure is passed as address_len. The length and format of the address depend on the address family. A particular address structure pointer will need to be cast to the generic address type (struct sockaddr *) in the call to bind. On successful completion, bind returns 0. If it fails, it returns -1 and sets errno to one of the following.<br /><br />
EBADF The file descriptor is invalid.<br />ENOTSOCK The file descriptor doesn’t refer to a socket.<br />EINVAL The file descriptor refers to an already-named socket.<br />EADDRNOTAVAIL The address is unavailable.<br />EADDRINUSE The address has a socket bound to it already. There are some more values for AF_UNIX sockets:<br />EACCESS Can’t create the file system name due to permissions.<br />ENOTDIR, ENAMETOOLONG Indicates a poor choice of filename.<br /><b> </b><br />
<b>Creating a Socket Queue</b><br /><br />
To accept incoming connections on a socket, a server program must create a queue to store pending requests. It does this using the listen system call.<br /><br />
#include <sys/socket.h><br />int listen(int socket, int backlog);<br /><br />
A Linux system may limit the maximum number of pending connections that may be held in a queue. Subject to this maximum, listen sets the queue length to backlog. Incoming connections up to this queue length are held pending on the socket; further connections will be refused and the client’s connection will fail. This mechanism is provided by listen to allow incoming connections to be held pending while a server program is busy dealing with a previous client. A value of 5 for backlog is very common. The listen function will return 0 on success or -1 on error. Errors include EBADF, EINVAL, and ENOTSOCK, as for the bind system call.<br /><br />
<b>Accepting Connections</b><br />
<b> </b><br />Once a server program has created and named a socket, it can wait for connections to be made to the socket by using the accept system call.<br /><br />
#include <sys/socket.h><br />int accept(int socket, struct sockaddr *address, size_t *address_len);<br /><br />
The accept system call returns when a client program attempts to connect to the socket specified by the parameter socket. The client is the first pending connection from that socket’s queue. The accept function creates a new socket to communicate with the client and returns its descriptor. The new socket will have the same type as the server listen socket. The socket must have previously been named by a call to bind and had a connection queue allocated by listen. The address of the calling client will be placed in the sockaddr structure pointed to by address. A null pointer may be used here if the client address isn’t of interest.<br />The address_len parameter specifies the length of the client structure. If the client address is longer than this value, it will be truncated. Before calling accept, address_len must be set to the expected address length. On return, address_len will be set to the actual length of the calling client’s address<br />structure.<br />If there are no connections pending on the socket’s queue, accept will block (so that the program won’t continue) until a client makes a connection. You may change this behavior by using the O_NONBLOCK flag on the socket file descriptor, using the fcntl function like this:<br />
<br />int flags = fcntl(socket, F_GETFL, 0);<br />fcntl(socket, F_SETFL, O_NONBLOCK|flags);<br />The accept function returns a new socket file descriptor when there is a client connection pending or -1 on error. Possible errors are similar to those for bind and listen, with the addition of EWOULDBLOCK, where O_NONBLOCK has been specified and there are no pending connections. The error EINTR will occur if the process is interrupted while blocked in accept.<br /><br />
<b>Requesting Connections</b><br /><br />
Client programs connect to servers by establishing a connection between an unnamed socket and the server listen socket. They do this by calling connect.<br />
<br />#include <sys/socket.h><br />int connect(int socket, const struct sockaddr *address, size_t address_len);<br /><br />
The socket specified by the parameter socket is connected to the server socket specified by the parameter address, which is of length address_len. The socket must be a valid file descriptor obtained by a call to socket.<br />
<br />
If it succeeds, connect returns 0, and -1 is returned on error. Possible errorsthis time include the following:<br />EBADF An invalid file descriptor was passed in socket.<br />EALREADY A connection is already in progress for this socket.<br />ETIMEDOUT A connection timeout has occurred.<br />ECONNREFUSED The requested connection was refused by the server.<br />If the connection can’t be set up immediately, connect will block for an unspecified timeout period.<br /><br />
Once this timeout has expired, the connection will be aborted and connect will fail. However, if the call to connect is interrupted by a signal that is handled, the connect call will fail (with errno set to EINTR), but the connection attempt won’t be aborted but rather will be set up asynchronously. As with accept, the blocking nature of connect may be altered by setting the O_NONBLOCK flag on the file descriptor. In this case, if the connection can’t be made immediately, connect will fail with errno<br />set to EINPROGRESS and the connection will be made asynchronously.<br />While asynchronous connections can be tricky to handle, you can use a call to select on the socket file descriptor to indicate that the socket is ready for writing.<br />
<br /><b>Closing a Socket</b><br /><br />
You can terminate a socket connection at the server and client by calling close, just as you would for low-level file descriptors. You should always close the socket at both ends. For the server, you should do this when read returns zero, but the close call could block if the socket has untransmitted data, is of a connection-oriented type, and has the SOCK_LINGER option set.<br />
<br /></div>Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com0tag:blogger.com,1999:blog-4224221485098744558.post-62704406746077511402012-05-24T10:11:00.000+05:302012-05-24T10:11:54.277+05:30Basics Of SOCKET<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<b>What Is a Socket?</b></h2>
A socket is a communication mechanism that allows client/server systems to be developed either locally, on a single machine, or across networks. Linux functions such as printing and network utilities such as rlogin and ftp usually use sockets to communicate. Sockets are created and used differently from pipes because they make a clear distinction between client<br />and server. The socket mechanism can implement multiple clients attached to a single server.<br />
<br />
<h3 style="text-align: left;">
<b>Socket Connections</b></h3>
<div style="text-align: left;">
<br /></div>
You can think of socket connections as telephone calls into a busy building. A call comes into an organi- zation and is answered by a receptionist who puts the call through to the correct department (the server process) and from there to the right person (the server socket). Each incoming call (client) is routed to an appropriate end point and the intervening operators are free to deal with further calls. Before you look at the way socket connections are established in Linux systems, you need to understand how they operate for socket applications that maintain a connection.<br />First of all, a server application creates a socket, which like a file descriptor is a resource assigned to the server process and that process alone. The server creates it using the system call socket, and it can’t be shared with other processes.<br />Next, the server process gives the socket a name. Local sockets are given a filename in the Linux file sys- tem, often to be found in /tmp or /usr/tmp. For network sockets, the filename will be a service identifier (port number/access point) relevant to the particular network to which the clients can connect. This identifier allows Linux to route incoming connections specifying a particular port number to the correct server process. A socket is named using the system call bind. The server process then waits for a client to connect to the named socket. The system call, listen, creates a queue for incoming connections. The server can accept them using the system call accept.<br />When the server calls accept, a new socket is created that is distinct from the named socket. This new socket is used solely for communication with this particular client. The named socket remains for further connections from other clients. If the server is written appropriately, it can take advantage of multiple connections. For a simple server, further clients wait on the listen queue until the server is ready again. The client side of a socket-based system is more straightforward. The client creates an unnamed socket by calling socket. It then calls connect to establish a connection with the server by using the server’s named socket as an address.<br />Once established, sockets can be used like low-level file descriptors, providing two-way data communications.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<h3 style="text-align: left;">
<b>Socket Attributes</b></h3>
<b> </b><br />To fully understand the system calls used in this example, you need to learn a little about UNIX networking.<br />Sockets are characterized by three attributes: domain, type, and protocol. They also have an address used as their name. The formats of the addresses vary depending on the domain, also known as the protocol family. Each protocol family can use one or more address families to define the address format.<br />
<br />
<h3 style="text-align: left;">
<b>Socket Domains</b></h3>
<b> </b><br />Domains specify the network medium that the socket communication will use. The most common socket domain is AF_INET, which refers to Internet networking that’s used on many Linux local area networks and, of course, the Internet itself. The underlying protocol, Internet Protocol (IP), which only has one address family, imposes a particular way of specifying computers on a network. This is called the IP address.<br />Although names almost always refer to networked machines on the Internet, these are translated into lower-level IP addresses. An example IP address is 192.168.1.99. All IP addresses are represented by four numbers, each less than 256, a so-called dotted quad. When a client connects across a network via sockets, it needs the IP address of the server computer.<br />There may be several services available at the server computer. A client can address a particular service on a networked machine by using an IP port. A port is identified within the system by assigning a unique 16-bit integer and externally by the combination of IP address and port number. The sockets are communication end points that must be bound to ports before communication is possible.<br />Servers wait for connections on particular ports. Well-known services have allocated port numbers that are used by all Linux and UNIX machines. These are usually, but not always, numbers less than 1024. Examples are the printer spooler (515), rlogin (513), ftp (21), and httpd (80). The last of these is the server for the World Wide Web (WWW). Usually, port numbers less than 1024 are reserved for system services and may only be served by processes with superuser privileges. X/Open defines a constant in netdb.h, IPPORT_RESERVED, to stand for the highest reserved port number. Because there is a standard set of port numbers for standard services, computers can easily connect to each other without having to establish the correct port. Local services may use nonstandard port addresses. The domain in our first example is the UNIX file system domain, AF_UNIX, which can be used by sockets based on a single computer that perhaps isn’t networked. When this is so, the underlying protocol is file input/output and the addresses are absolute filenames. The address that you used for the server socket was server_socket, which you saw appear in the current directory when you ran the server application.<br />Other domains that might be used include AF_ISO for networks based on ISO standard protocols and AF_XNS for the Xerox Network System. We won’t cover these here.<br /><br />
<h3 style="text-align: left;">
<b>Socket Types</b></h3>
<br />A socket domain may have a number of different ways of communicating, each of which might have different characteristics. This isn’t an issue with AF_UNIX domain sockets, which provide a reliable two- way communication path. In networked domains, however, you need to be aware of the characteristics of the underlying network. Internet protocols provide two distinct levels of service: streams and datagrams.<br /><br />
<h4 style="text-align: left;">
<b>Stream Sockets</b></h4>
<br />
Stream sockets (in some ways similar to standard input/output streams) provide a connection that is a sequenced and reliable two-way byte stream. Thus, data sent is guaranteed not to be lost, duplicated, or reordered without an indication that an error has occurred. Large messages are fragmented, transmitted, and reassembled. This is like a file stream, as it accepts large amounts of data and writes it to the low- level disk in smaller blocks. Stream sockets have predictable behavior.<br />Stream sockets, specified by the type SOCK_STREAM, are implemented in the AF_INET domain by TCP/IP connections. They are also the usual type in the AF_UNIX domain. We’ll concentrate on SOCK_STREAM sockets in this chapter because they are more commonly used in programming network<br />applications.<br />TCP/IP stands for Transmission Control Protocol/Internet Protocol. IP is the low-level protocol for packets that provides routing through the network from one computer to another. TCP provides sequencing, flow control, and retransmission to ensure that large data transfers arrive with all of the data present and correct or with an appropriate error condition reported.<br /><b> </b><br />
<h4 style="text-align: left;">
<b>Datagram Sockets</b></h4>
In contrast, a datagram socket, specified by the type SOCK_DGRAM, doesn’t establish and maintain a connection. There is also a limit on the size of a datagram that can be sent. It’s transmitted as a single network message that may get lost, duplicated, or arrive out of sequence—ahead of datagrams sent after it.<br />Datagram sockets are implemented in the AF_INET domain by UDP/IP connections and provide anunsequenced, unreliable service. However, they are relatively inexpensive in terms of resources, since network connections need not be maintained. They’re fast because there is no associated connection setup time. UDP stands for User Datagram Protocol. Datagrams are useful for “single-shot” inquiries to information services, for providing regular status information, or for performing low-priority logging. They have the advantage that the death of a server doesn’t necessarily require a client restart. Because datagram-based servers usually retain no connection<br />information, they can be stopped and restarted without unduly disturbing their clients. For now, we leave the topic of datagrams; see the “Datagrams” section near the end of this chapter for more information on datagrams.<br /></div>Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com0tag:blogger.com,1999:blog-4224221485098744558.post-1518324383962112412012-05-10T17:17:00.002+05:302012-05-15T16:51:36.449+05:30Shared Memory<div dir="ltr" style="text-align: left;" trbidi="on">
<style type="text/css">
<!--
@page { margin: 0.79in }
P { margin-bottom: 0.08in }
-->
</style>
<br />
<div align="CENTER" style="line-height: 100%; margin-bottom: 0in;">
<br /></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">Shared
memory allows two
unrelated processes to access the same logical memory. Shared memory
is a very efficient way of transferring data between two running
processes. Although the X/Open standard doesn’t require it, it’s
probable that most implementations of shared memory arrange for the
memory being shared between different processes to be the same
physical memory.</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">Shared
memory provides an efficient way of sharing and passing data between
multiple processes. Since it provides no synchronization facilities,
we usually need to use some other mechanism to synchronize access to
the shared memory. Typically, we might use shared memory to provide
efficient access to large areas of memory and pass small messages to
synchronize access to that memory.</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">Shared
memory is a special range of addresses that is created by IPC for one
process and appears in the address space of that process. Other
processes can then “attach” the same shared memory segment into
their own address space. All processes can access the memory
locations just as if the memory had been allocated by </span><span style="font-size: small;">malloc</span><span style="font-size: small;">.
If one process writes to the shared memory, the changes immediately
become visible to any other process that has access to the same
shared memory.</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<br />
</div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">The
functions for shared memory resemble those for semaphores:</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<br />
</div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;"><b>#include
<sys/shm.h></b></span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">void
*shmat(int shm_id, const void *shm_addr, int shmflg);</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">int
shmctl(int shm_id, int cmd, struct shmid_ds *buf);</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">int
shmdt(const void *shm_addr);</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">int
shmget(key_t key, size_t size, int shmflg);</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<br />
</div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">As with
semaphores, the </span><span style="font-size: small;">include </span><span style="font-size: small;">files
</span><span style="font-size: small;">sys/types.h </span><span style="font-size: small;">and </span><span style="font-size: small;">sys/ipc.h
</span><span style="font-size: small;">are normally also required before </span><span style="font-size: small;">shm.h
</span><span style="font-size: small;">is included.</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<br />
</div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;"><b>shmget</b></span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">We
create shared memory using the </span><span style="font-size: small;">shmget </span><span style="font-size: small;">function:</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">int
shmget(key_t key, size_t size, int shmflg);</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">As with
semaphores, the program provides </span><span style="font-size: small;">key</span><span style="font-size: small;">,
which effectively names the shared memory segment, and the </span><span style="font-size: small;">shmget
</span><span style="font-size: small;">function returns a shared memory identifier that
is used in subsequent shared memory functions. There’s a special
key value, </span><span style="font-size: small;">IPC_PRIVATE</span><span style="font-size: small;">, that
creates shared memory private to the process. You wouldn’t normally
use this value, and, as with semaphores, you may find the private
shared memory is not actually private on many Linux systems. The
second parameter, </span><span style="font-size: small;">size</span><span style="font-size: small;">,
specifies the amount of memory required in bytes. The third
parameter, </span><span style="font-size: small;">shmflg</span><span style="font-size: small;">, consists
of nine permission flags that are used in the same way as the mode
flags for creating files. Aspecial bit defined by </span><span style="font-size: small;">IPC_CREAT
</span><span style="font-size: small;">must be bitwise ORed with the permissions to
create a new shared memory segment. It’s not an error to have the
</span><span style="font-size: small;">IPC_CREAT </span><span style="font-size: small;">flag set and pass
the key of an existing shared memory segment. The </span><span style="font-size: small;">IPC_CREAT
</span><span style="font-size: small;">flag is silently ignored if it is not required.
The permission flags are very useful with shared memory because they
allow a process to create shared memory that can be written by
processes owned by the creator of the shared memory but only read by
processes that other users have created. We can use this to provide
efficient read-only access to data by placing it in shared memory
without the risk of its being changed by other users. If the shared
memory is successfully created, </span><span style="font-size: small;">shmget </span><span style="font-size: small;">returns
a nonnegative integer, the shared memory identifier. On failure, it
returns –1.</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<br />
</div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;"><b>shmat</b></span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">When we
first create a shared memory segment, it’s not accessible by any
process. To enable access to the shared memory, we must attach it to
the address space of a process. We do this with the </span><span style="font-size: small;">shmat
</span><span style="font-size: small;">function:</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">void
*shmat(int shm_id, const void *shm_addr, int shmflg);</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">The
first parameter, </span><span style="font-size: small;">shm_id</span><span style="font-size: small;">, is
the shared memory identifier returned from </span><span style="font-size: small;">shmget</span><span style="font-size: small;">.
The second parameter, </span><span style="font-size: small;">shm_addr</span><span style="font-size: small;">,
is the address at which the shared memory is to be attached to the
current process. This should almost always be a null pointer, which
allows the system to choose the address at which the memory appears.
The third parameter, </span><span style="font-size: small;">shmflg</span><span style="font-size: small;">,
is a set of bitwise flags. The two possible values are </span><span style="font-size: small;">SHM_RND</span><span style="font-size: small;">,
which, in conjunction with </span><span style="font-size: small;">shm_addr</span><span style="font-size: small;">,
controls the address at which the shared memory is attached, and
</span><span style="font-size: small;">SHM_RDONLY</span><span style="font-size: small;">, which makes the
attached memory read-only. It’s very rare to need to control the
address at which shared memory is attached; you should normally allow
the system to choose an address for you, as doing otherwise will make
the application highly hardware-dependent. If the </span><span style="font-size: small;">shmat
</span><span style="font-size: small;">call is successful, it returns a pointer to the
first byte of shared memory. On failure –1 is returned.</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">The
shared memory will have read or write access depending on the owner
(the creator of the shared memory), the permissions, and the owner of
the current process. Permissions on shared memory are similar to the
permissions on files. An exception to this rule arises if </span><span style="font-size: small;">shmflg
& SHM_RDONLY </span><span style="font-size: small;">is </span><span style="font-size: small;">true</span><span style="font-size: small;">.
Then the shared memory won’t be writable, even if permissions would
have allowed write access.</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<br />
</div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;"><b>shmdt</b></span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">The
</span><span style="font-size: small;">shmdt </span><span style="font-size: small;">function detaches the
shared memory from the current process. It takes a pointer to the
address returned by </span><span style="font-size: small;">shmat</span><span style="font-size: small;">. On
success, it returns 0, on error –1. Note that detaching the shared
memory doesn’t delete it; it just makes that memory unavailable to
the current process.</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;"><b>shmctl</b></span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">The
control functions for shared memory are (thankfully) somewhat simpler
than the more complex ones for semaphores:</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">int
shmctl(int shm_id, int command, struct shmid_ds *buf);</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">The
</span><span style="font-size: small;">shmid_ds </span><span style="font-size: small;">structure has at
least the following members:</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">struct
shmid_ds {</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">uid_t
shm_perm.uid;</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">uid_t
shm_perm.gid;</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">mode_t
shm_perm.mode;</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">}</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">The
first parameter, </span><span style="font-size: small;">shm_id</span><span style="font-size: small;">, is
the identifier returned from </span><span style="font-size: small;">shmget</span><span style="font-size: small;">.</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<br />
</div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">The
first parameter, </span><span style="font-size: small;">shm_id</span><span style="font-size: small;">, is
the identifier returned from </span><span style="font-size: small;">shmget</span><span style="font-size: small;">.
The second parameter, </span><span style="font-size: small;">command</span><span style="font-size: small;">,
is the action to take. It can take three values:</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<br />
</div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;"><b>Command
Description</b></span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;"><b>IPC_STAT</b></span><span style="font-size: small;">
</span><span style="font-size: small;">Sets the data in the </span><span style="font-size: small;">shmid_ds
</span><span style="font-size: small;">structure to reflect the values associated with
the shared memory.</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;"><b>IPC_SET</b></span><span style="font-size: small;">
</span><span style="font-size: small;">Sets the values associated with the shared memory
to those provided in the </span><span style="font-size: small;">shmid_ds </span><span style="font-size: small;">data
structure, if the process has permission to do so.</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;"><b>IPC_RMID</b></span><span style="font-size: small;">
</span><span style="font-size: small;">Deletes the shared memory segment.</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<br />
</div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">The
third parameter, </span><span style="font-size: small;">buf</span><span style="font-size: small;">, is a
pointer to structure containing the modes and permissions for the
shared memory.</span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<br />
</div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-size: small;">On
success, it returns 0, on failure, –1. X/Open doesn’t specify
what happens if you attempt to delete a shared memory segment while
it’s attached. Generally, a shared memory segment that is attached
but deleted continues to function until it has been detached from the
last process. However, because this behavior isn’t specified, it’s
best not to rely on it.</span></div>
</div>Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com0tag:blogger.com,1999:blog-4224221485098744558.post-58948676326899459312012-04-25T17:05:00.000+05:302012-05-15T16:51:36.636+05:30message queue<div dir="ltr" style="text-align: left;" trbidi="on">
<br />We’ll now take a look at the third and final System V IPC facility: message queues. In many ways, message queues are like named pipes, but without the complexity associated with opening and closing the pipe. However, using messages doesn’t get us away from the problems that we have with named pipes, such as blocking on full pipes. Message queues provide a reasonably easy and efficient way of passing data between two unrelated processes. They have the advantage over named pipes that the message queue exists independently of both the sending and receiving processes, which removes some of the difficulties that occur in synchronizing the opening and closing of named pipes.<br /><br />Message queues provide a way of sending a block of data from one process to another. Additionally, each block of data is considered to have a type, and a receiving process may receive blocks of data having different type values independently. The good news is that we can almost totally avoid the synchronization and blocking problems of named pipes by sending messages. Even better, we can “look ahead” for messages that are urgent in some way. The bad news is that, just like pipes, there’s a maximum size limit imposed on each block of data and also a limit on the maximum total size of all blocks on all queues throughout the system.<br />While stating that these limits are imposed, the X/Open specification offers no way of discovering what the limits are, except that exceeding them is a valid reason for some message queue functions to fail. Linux does have two defines, MSGMAX and MSGMNB, which define the maximum size in bytes of an individual message and the maximum size of a queue, respectively. These macros may be different or, for that matter, not even present on other systems.<br />The message queue function definitions are<br /><br /> #include <sys/msg.h><br />int msgctl(int msqid, int cmd, struct msqid_ds *buf);<br />int msgget(key_t key, int msgflg);<br />int msgrcv(int msqid, void *msg_ptr, size_t msg_sz, long int msgtype, int msgflg);<br />int msgsnd(int msqid, const void *msg_ptr, size_t msg_sz, int msgflg);<br /><br /><b>msgget</b><br />We create and access a message queue using the msgget function:<br />int msgget(key_t key, int msgflg);<br />The program must provide a key value that, as with other IPC facilities, names a particular message queue. The special value IPC_PRIVATE creates a private queue, which in theory is accessible only by the current process. As with semaphores and messages, on some Linux systems the message queue may not actually be private. Since a private queue has very little purpose, that’s not a significant problem. As before, the second parameter, msgflg, consists of nine permission flags. Aspecial bit defined by IPC_CREAT must be bitwise ORed with the permissions to create a new message queue. It’s not an error to set the IPC_CREAT flag and give the key of an existing message queue. The IPC_CREAT flag is silently ignored if the message queue already exists. The msgget function returns a positive number, the queue identifier, on success or –1 on failure.<br /><br /><b>msgsnd</b><br />The msgsnd function allows us to add a message to a message queue:<br />int msgsnd(int msqid, const void *msg_ptr, size_t msg_sz, int msgflg);<br />The structure of the message is constrained in two ways. First, it must be smaller than the system limit, and second, it must start with a long int, which will be used as a message type in the receive function. When you’re using messages, it’s best to define your message structure something like this:<br />struct my_message {<br />long int message_type;<br />/* The data you wish to transfer */<br />}<br />Since the message_type is used in message reception, you can’t simply ignore it. You must declare your data structure to include it, and it’s also wise to initialize it, so that it contains a known value. The first parameter, msqid, is the message queue identifier returned from a msgget function. The second parameter, msg_ptr, is a pointer to the message to be sent, which must start with a long int type as described previously.<br />The third parameter, msg_sz, is the size of the message pointed to by msg_ptr. This size must not<br />include the long int message type. The fourth parameter, msgflg, controls what happens if either the current message queue is full or the systemwide limit on queued messages has been reached. If msgflg has the IPC_NOWAIT flag set, the function will return immediately without sending the message and the return value will be –1. If the msgflg has the IPC_NOWAIT flag clear, the sending process will be suspended, waiting for space to become available in the queue. On success, the function returns 0, on failure –1. If the call is successful, a copy of the message data has been taken and placed on the message queue.<br /><br /><b>msgrcv</b><br />The msgrcv function retrieves messages from a message queue:<br />int msgrcv(int msqid, void *msg_ptr, size_t msg_sz, long int msgtype, int msgflg);<br />The first parameter, msqid, is the message queue identifier returned from a msgget function.<br />The second parameter, msg_ptr, is a pointer to the message to be received, which must start with a long int type as described above in the msgsnd function.<br />The third parameter, msg_sz, is the size of the message pointed to by msg_ptr, not including the long int message type.<br />The fourth parameter, msgtype, is a long int, which allows a simple form of reception priority to be implemented. If msgtype has the value 0, the first available message in the queue is retrieved. If it’s greater than zero, the first message with the same message type is retrieved. If it’s less than zero, the first message that has a type the same as or less than the absolute value of msgtype is retrieved. This sounds more complicated than it actually is in practice. If you simply want to retrieve messages in the order in which they were sent, set msgtype to 0. If you want to retrieve only messages with a specific message type, set msgtype equal to that value. If you want to receive messages with a type of n or smaller, set msgtype to -n. The fifth parameter, msgflg, controls what happens when no message of the appropriate type is waiting to be received. If the IPC_NOWAIT flag in msgflg is set, the call will return immediately with a return value of –1. If the IPC_NOWAIT flag of msgflg is clear, the process will be suspended, waiting for an appropriate type of message to arrive.<br />On success, msgrcv returns the number of bytes placed in the receive buffer, the message is copied into the user-allocated buffer pointed to by msg_ptr, and the data is deleted from the message queue. It returns –1 on error.<br /><br /><b>msgctl</b><br />The final message queue function is msgctl, which is very similar to that of the control function for<br />shared memory.<br />int msgctl(int msqid, int command, struct msqid_ds *buf);<br />The msqid_ds structure has at least the following members:<br />struct msqid_ds {<br />uid_t msg_perm.uid;<br />uid_t msg_perm.gid<br />mode_t msg_perm.mode;<br />}<br />The first parameter, msqid, is the identifier returned from msgget.<br />The second parameter, command, is the action to take. It can take three values:<br /><br />Command Description<br />IPC_STAT Sets the data in the msqid_ds structure to reflect the values associated with the message queue.<br />IPC_SET If the process has permission to do so, this sets the values associated with the message queue to those provided in the msqid_ds data structure.<br />IPC_RMID Deletes the message queue.<br />0 is returned on success, –1 on failure. If a message queue is deleted while a process is waiting in a msgsnd or msgrcv function, the send or receive function will fail.<br /></div>Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com0tag:blogger.com,1999:blog-4224221485098744558.post-87960063679385927282012-04-25T13:39:00.001+05:302012-05-15T16:51:36.736+05:30Signal Handling in Linux<div dir="ltr" style="text-align: left;" trbidi="on">
Signals have a very precise lifecycle. First, a signal is raised (we sometimes also say it is sent or generated). The kernel then stores the signal until it is able to deliver it.<br />Finally, once it is free to do so, the kernel handles the signal as appropriate. The kernel can perform one of three actions, depending on what the process asked it to do:<br /><br /><b>Ignore the signal</b><br />No action is taken. There are two signals that cannot be ignored: SIGKILL and SIGSTOP. The reason for this is that the system administrator needs to be able to kill or stop processes, and it would be a circumvention of that right if a process could elect to ignore a SIGKILL (making it unkillable), or a SIGSTOP (making it unstoppable).<br /><br /><b>Catch and handle the signal</b><br />The kernel will suspend execution of the process’ current code path, and jump to a previously registered function. The process will then execute this function. Once the process returns from this function, it will jump back to wherever it was when it caught the signal. SIGINT and SIGTERM are two commonly caught signals. Processes catch SIGINT to handle the user generating the interrupt character—for example, a terminal might catch this signal and return to the main prompt. Processes catch SIGTERM to perform necessarily cleanup, such as disconnecting from the network, or removing temporary files, before terminating. SIGKILL and SIGSTOP cannot be caught.<br /><b><br />Perform the default action</b><br />This action depends on the signal being sent. The default action is often to terminate the process. This is the case with SIGKILL, for instance. However, many signals are provided for specific purposes that concern programmers in particular situations, and these signals are ignored by default because many programs are not interested in them. We will look at the various signals and their default actions shortly.<br /><br />Traditionally, when a signal was delivered, the function that handled the signal had no information about what had happened except for the fact that a particular signal had occurred. Nowadays, the kernel can provide a lot of context to programmers who want to receive it, and signals can even pass user-defined data, like later and more advanced IPC mechanisms.<br /><b><br />Signals Used in Linux :</b><br /><br />1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP<br /> 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1<br />11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM<br />16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP<br />21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ<br />26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR<br />31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3<br />38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8<br />43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 <br />47) SIGRTMIN+13 48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 <br />51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10 <br />55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6 <br />59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2<br />63) SIGRTMAX-1 64) SIGRTMAX<br /><br /><br />The numbers in this shows the Signals number. Which we used during the programming.<br /><br /><b>Signal Handling</b><br />#include <signal.h><br />#include <stdio.h><br />#include <unistd.h><br /><br /><b>void signal_handler(int sig)</b><br />{<br />printf(“ I got signal %d\n”, sig);<br />(void) signal(SIGINT, SIG_DFL);<br />}<br />int main()<br />{<br /><b>(void) signal(SIGINT, signal_handler);</b><br />while(1) <br />{<br />printf(“Hello World!\n”);<br />sleep(1);<br />}<br />return 0;<br />}<br />$ ./ctrlc1<br />Hello World!<br />Hello World!<br />Hello World!<br />Hello World!<br />^C<br />-I got signal 2<br />Hello World!<br />Hello World!<br />Hello World!<br />Hello World!<br />^C<br />$<br />As you can see from this example, the signal handling function takes a single integer parameter, the signal number that caused the function to be called. This can be useful if the same function is used to handle more than one signal. Here we print out the value of SIGINT, which on this system happens to have the value 2. You shouldn’t rely on traditional numeric values for signals; always use signal names in new programs.<br /><br />It is not safe to call all functions, such as printf, from within a signal handler. A useful technique is to use a signal handler to set a flag and then check that flag from the main program and print a message if required. Toward the end of the chapter, you will find a list of calls that can safely be made inside signal handlers.<br /><b><br />Sending Signals</b><br />A process may send a signal to another process, including itself, by calling kill. The call will fail if the program doesn’t have permission to send the signal, often because the target process is owned by another user. This is the program equivalent of the shell command of the same name.<br /><br />#include <sys/types.h><br />#include <signal.h><br />int kill(pid_t pid, int sig);<br /><br />The kill function sends the specified signal, sig, to the process whose identifier is given by pid. It returns 0 on success. To send a signal, the sending process must have permission to do so. Normally, this means that both processes must have the same user ID (that is, you can send a signal only to one of your own processes, although the superuser may send signals to any process). kill will fail, return -1, and set errno if the signal given is not a valid one (errno set to EINVAL), if it doesn’t have permission (EPERM), or if the specified process doesn’t exist (ESRCH).<br /></div>Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com0tag:blogger.com,1999:blog-4224221485098744558.post-26877111486029732402012-04-25T13:20:00.003+05:302012-05-15T16:51:36.492+05:30Semaphores: A synchronization mechnism<div dir="ltr" style="text-align: left;" trbidi="on">
<br /><br />When we write programs that use threads operating in multiuser systems, multiprocessing systems, or a combination of the two, we often discover that we have critical sections of code, where we need to ensure that a single process (or a single thread of execution) has exclusive access to a resource. Semaphores have a complex programming interface. Fortunately, we can easily provide ourselves with a much-simplified interface that is sufficient for most semaphore-programming problems. a semaphore is a special variable that takes only whole positive numbers and upon which only two operations are allowed: wait and signal. Since “wait” and “signal” already have special meanings in Linux and UNIX programming, we’ll use the original notation:<br /><br />❑ P(semaphore variable) for wait<br />❑ V(semaphore variable) for signal<br /><br />These letters come from the Dutch words for wait (passeren: to pass, as in a checkpoint before the critical section) and signal (vrijgeven: to give or release, as in giving up control of the critical section). You may also come across the terms “up” and “down” used in relation to semaphores, taken from the use of signaling flags.<br /><br />Semaphore Definition<br /><br />The simplest semaphore is a variable that can take only the values 0 and 1, a binary semaphore. This is the most common form. Semaphores that can take many positive values are called general semaphores. For the remainder of this chapter, we’ll concentrate on binary semaphores.<br />The definitions of P and V are surprisingly simple. Suppose we have a semaphore variable sv. The two operations are then defined as follows:<br />P(sv) If sv is greater than zero, decrement sv. If sv is zero, suspend execution of this process.<br />V(sv) If some other process has been suspended waiting for sv, make it resume execution. If no process is suspended waiting for sv, increment sv.<br />Another way of thinking about semaphores is that the semaphore variable, sv, is true when the critical section is available, is decremented by P(sv) so it’s false when the critical section is busy, and is incremented by V(sv) when the critical section is again available. Be aware that simply having a normal variable that you decrement and increment is not good enough, because you can’t express in C, C++, or almost any conventional programming language the need to make a single, atomic operation of the test to see whether the variable is true, and if so change the variable to make it false. This is what makes the semaphore operations special.<br /><br />Linux Semaphore Facilities<br /><br />Now that we’ve seen what semaphores are and how they work in theory, we can look at how the features are implemented in Linux. The interface is rather elaborate and offers far more facilities than are generally required. All the Linux semaphore functions operate on arrays of general semaphores rather than a single binary semaphore. At first sight, this just seems to make things more complicated, but in complex cases where a process needs to lock multiple resources, the ability to operate on an array of semaphores is a big advantage. In this chapter, we will concentrate on using single semaphores, since in most cases that’s all you will need to use.<br />The semaphore function definitions are<br /><br />#include <sys/sem.h><br />int semctl(int sem_id, int sem_num, int command, ...);<br />int semget(key_t key, int num_sems, int sem_flags);<br />int semop(int sem_id, struct sembuf *sem_ops, size_t num_sem_ops);<br /><br />As we work through each function in turn, remember that these functions were designed to work for arrays of semaphore values, which makes their operation significantly more complex than would have been required for a single semaphore.<br />Notice that key acts very much like a filename in that it represents a resource that programs may use and cooperate in using if they agree on a common name. Similarly, the identifier returned by semget and used by the other shared memory functions is very much like the FILE * file stream returned by fopen in that it’s a value used by the process to access the shared file. And, just as with files, different processes will have different semaphore identifiers, though they refer to the same semaphore. This use of a key and identifiers is common to all of the IPC facilities discussed here, although each facility uses independent keys and identifiers.<br /><br />Semget<br /><br />The semget function creates a new semaphore or obtains the semaphore key of an existing semaphore.<br /><br />int semget(key_t key, int num_sems, int sem_flags);<br /><br />The first parameter, key, is an integral value used to allow unrelated processes to access the same semaphore. All semaphores are accessed indirectly by the program supplying a key, for which the system then generates a semaphore identifier. The semaphore key is used only with semget. All other semaphore functions use the semaphore identifier returned from semget.<br />There is a special semaphore key value, IPC_PRIVATE (usually 0), that is intended to create a semaphore that only the creating process could access. This rarely has any useful purpose, which is fortunate, because on some Linux systems the manual pages list as a bug the fact that IPC_PRIVATE may not prevent other processes from accessing the semaphore. The num_sems parameter is the number of semaphores required. This is almost always 1. The sem_flags parameter is a set of flags, very much like the flags to the open function. The lower nine bits are the permissions for the semaphore, which behave like file permissions. In addition, these can be bitwise ORed with the value IPC_CREAT to create a new semaphore. It’s not an error to have the IPC_CREAT flag set and give the key of an existing semaphore. The IPC_CREAT flag is silently ignored if it is not required. We can use IPC_CREAT and IPC_EXCL together to ensure that we obtain a new, unique semaphore. It will return an error if the semaphore already exists.<br />The semget function returns a positive (nonzero) value on success; this is the semaphore identifier used in the other semaphore functions. On error, it returns –1.<br /><br />semop<br /><br />The function semop is used for changing the value of the semaphore:<br /><br />int semop(int sem_id, struct sembuf *sem_ops, size_t num_sem_ops);<br /><br />The first parameter, sem_id, is the semaphore identifier, as returned from semget. The second parameter,<br />sem_ops, is a pointer to an array of structures, each of which will have at least the following members:<br /><br />struct sembuf {<br />short sem_num;<br />short sem_op;<br />short sem_flg;<br />}<br /><br />The first member, sem_num, is the semaphore number, usually 0 unless you’re working with an array of semaphores. The sem_op member is the value by which the semaphore should be changed. (You can change a semaphore by amounts other than 1.) In general, only two values are used, –1, which is our P operation to wait for a semaphore to become available, and +1, which is our V operation to signal that a semaphore is now available. The final member, sem_flg, is usually set to SEM_UNDO. This causes the operating system to track the changes made to the semaphore by the current process and, if the process terminates without releasing the semaphore, allows the operating system to automatically release the semaphore if it was held by this process. It’s good practice to set sem_flg to SEM_UNDO, unless you specifically require different behavior. If you do decide you need a value other than SEM_UNDO, it’s important to be consistent, or you can get very confused as to whether the kernel is attempting to “tidy up” your semaphores when your process exits. All actions called for by semop are taken together to avoid a race condition implied by the use of multiple semaphores. You can find full details of the processing of semop in the manual pages.<br /><br />Semctl<br /><br />The semctl function allows direct control of semaphore information:<br />int semctl(int sem_id, int sem_num, int command, ...);<br />The first parameter, sem_id, is a semaphore identifier, obtained from semget. The sem_num parameter is the semaphore number. You use this when you’re working with arrays of semaphores. Usually, this is 0, the first and only semaphore. The command parameter is the action to take, and a fourth parameter, if present, is a union semun, which according to the X/OPEN specification, must have at least the following members:<br /><br />union semun {<br />int val;<br />struct semid_ds *buf;<br />unsigned short *array;<br />}<br />Many versions of Linux have a definition of the semun union in a header file (usually sem.h), though X/Open does say that you have to declare your own. If you do find that you need to declare your own, check the manual pages for semctl to see if there is a definition given. If there is, we suggest you use exactly the definition given in your manual, even if it differs from that above. There are many different possible values of command allowed for semctl. Only the two that we describe here are commonly used. For full details of the semctl function, you should consult the manual page. The two common values of command are<br />❑ SETVAL: Used for initializing a semaphore to a known value. The value required is passed as<br />the val member of the union semun. This is required to set the semaphore up before it’s used for the first time.<br />❑ IPC_RMID: Used for deleting a semaphore identifier when it’s no longer required. The semctl function returns different values depending on the command parameter. For SETVAL and IPC_RMID it returns 0 for success and –1 on error.<br /></div>Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com0tag:blogger.com,1999:blog-4224221485098744558.post-49252694424469355342012-04-02T14:06:00.002+05:302012-05-15T16:51:36.608+05:30File I/O : system calls<div dir="ltr" style="text-align: left;" trbidi="on">
<b>File I/O</b><br /><br /><b>Opening Files</b><br /><br />The most basic method of accessing a file is via the read( ) and write( ) system calls. Before a file can be accessed, however, it must be opened via an open( ) or creat( ) system call. Once done using the file, it should be closed using the system call close( ).<br /><br />The open( ) System Call<br /><br />A file is opened, and a file descriptor is obtained with the open( ) system call:<br /><br />#include <sys/types.h><br />#include <sys/stat.h><br />#include <fcntl.h><br /><br />int open (const char *name, int flags);<br />int open (const char *name, int flags, mode_t mode);<br /><br /><br />The open( ) system call maps the file given by the pathname name to a file descriptor, which it returns on success. The file position is set to zero, and the file is opened for access according to the flags given by flags.<br /><br />Flags for open( )<br /><br />The flags argument must be one of O_RDONLY, O_WRONLY, or O_RDWR. Respectively, these arguments request that the file be opened only for reading, only for writing, or for both reading and writing.<br /><br />For example, the following code opens /home/vineet/test for reading:<br /><br />Int fd;<br />fd = open ("/home/vineet/test", O_RDONLY);<br />if (fd == -1)<br />/* error */<br /> A file opened only for writing cannot also be read, and vice versa. The process issuing the open( ) system call must have sufficient permissions to obtain the access requested.<br /><br />The flags argument can be bitwise-ORed with one or more of the following values, modifying the behavior of the open request:<br /><br />O_APPEND<br /> The file will be opened in append mode. That is, before each write, the file position will be updated to point to the end of the file. This occurs even if another process has written to the file after the issuing process’ last write, thereby changing the file position.<br /><br />O_ASYNC<br />A signal (SIGIO by default) will be generated when the specified file becomes readable or writable. This flag is available only for terminals and sockets, not for regular files.<br /><br />O_CREAT<br />If the file denoted by name does not exist, the kernel will create it. If the file already exists, this flag has no effect unless O_EXCL is also given.<br /><br />O_DIRECT<br />The file will be opened for direct I/O .<br /><br />O_DIRECTORY<br />If name is not a directory, the call to open( ) will fail. This flag is used internally by the opendir( ) library call.<br /><br />O_EXCL<br />When given with O_CREAT, this flag will cause the call to open( ) to fail if the file given by name already exists. This is used to prevent race conditions on file creation.<br /><br />O_LARGEFILE<br />The given file will be opened using 64-bit offsets, allowing files larger than two gigabytes to be opened. This is implied on 64-bit architectures.<br /><br />O_NOCTTY<br />If the given name refers to a terminal device (say, /dev/tty), it will not become the process controlling terminal, even if the process does not currently have a controlling terminal. This flag is not frequently used.<br /><br />O_NOFOLLOW<br />If name is a symbolic link, the call to open( ) will fail. Normally, the link is resolved, and the target file is opened. If other components in the given path are links, the call will still succeed. For example, if name is /etc/ship/plank.txt, the call will fail if plank.txt is a symbolic link. It will succeed, however, if etc or ship is a symbolic link, so long as plank.txt is not.<br /><br />O_NONBLOCK<br />If possible, the file will be opened in nonblocking mode. Neither the open( ) call, nor any other operation will cause the process to block (sleep) on the I/O. This behavior may be defined only for FIFOs.<br /><br />O_SYNC<br />The file will be opened for synchronous I/O. No write operation will complete until the data has been physically written to disk; normal read operations are already synchronous, so this flag has no effect on reads. POSIX additionally defines O_DSYNC and O_RSYNC; on Linux, these flags are synonymous with O_SYNC.<br /><br />O_TRUNC<br />If the file exists, it is a regular file, and the given flags allow for writing, the file will be truncated to zero length. Use of O_TRUNC on a FIFO or terminal device is ignored. Use on other file types is undefined. Specifying O_TRUNC with O_RDONLY is also undefined, as you need write access to the file in order to truncate it.<br /><br />For example, the following code opens for writing the file /home/teach/pearl. If the file already exists, it will be truncated to a length of zero. Because the O_CREAT flag is not specified, if the file does not exist, the call will fail:<br /><br />int fd;<br />fd = open ("/home/vineet/test1", O_WRONLY | O_TRUNC);<br />if (fd == -1)<br />/* error */<br /><br /><br /><br /><b>Owners of New Files</b><br /><br />S_IRWXU<br />Owner has read, write, and execute permission.<br />S_IRUSR<br />Owner has read permission.<br />S_IWUSR<br />Owner has write permission.<br />S_IXUSR<br />Owner has execute permission.<br />S_IRWXG<br />Group has read, write, and execute permission.<br />S_IRGRP<br />Group has read permission.<br />S_IWGRP<br />Group has write permission.<br />S_IXGRP<br />Group has execute permission.<br />S_IRWXO<br />Everyone else has read, write, and execute permission.<br />S_IROTH<br />Everyone else has read permission.<br /><br />S_IWOTH<br />Everyone else has write permission.<br />S_IXOTH<br />Everyone else has execute permission.<br /><br /><br /><br /><b>The creat( ) Function</b><br /><br />The combination of O_WRONLY | O_CREAT | O_TRUNC is so common that a system call exists to provide just that behavior:<br /><br />#include <sys/types.h><br />#include <sys/stat.h><br />#include <fcntl.h><br /><br />int creat (const char *name, mode_t mode);<br /><br /><br />Return Values and Error Codes<br />Both open( ) and creat( ) return a file descriptor on success. On error, both return -1, and set errno to an appropriate error value (Chapter 1 discussed errno and listed the potential error values). Handling an error on file open is not complicated, as generally there will have been few or no steps performed prior to the open that need to be undone. A typical response would be prompting the user for a different filename or<br />simply terminating the program.<br /><br /><br /><b>Reading via read( )</b><br /><br />The most basic—and common—mechanism used for reading is the read( ) system call.<br /><br />#include <unistd.h><br />ssize_t read (int fd, void *buf, size_t len);<br /><br />Each call reads up to len bytes into buf from the current file offset of the file referenced by fd. On success, the number of bytes written into buf is returned. On error, the call returns -1, and errno is set. The file position is advanced by the number of bytes read from fd. If the object represented by fd is not capable of seeking (for example, a character device file), the read always occurs from the “current” position.<br />Basic usage is simple. This example reads from the file descriptor fd into word . The number of bytes read is equal to the size of the unsigned long type, which is four bytes on 32-bit Linux systems, and eight bytes on 64-bit systems. On return, nr contains the number of bytes read, or -1 on error:<br /><br /><br />unsigned long word;<br />ssize_t nr;<br /><br />/* read a couple bytes into 'word' from 'fd' */<br />nr = read (fd, &word, sizeof (unsigned long));<br />if (nr == -1)<br />/* error */<br /><br /> There are two problems with this -ve implementation: the call might return without reading all len bytes, and it could produce certain errors that this code does not check for and handle.<br /><br /><b>Writing with write( )</b><br /><br />The most basic and common system call used for writing is write( ). write( ) is the counterpart of read( ).<br /><br />#include <unistd.h><br />ssize_t write (int fd, const void *buf, size_t count);<br /><br />A call to write( ) writes up to count bytes starting at buf to the current file position of the file referenced by the file descriptor fd. Files backed by objects that do not support seeking (for example, character devices) always write starting at the “head.”<br /><br />On success, the number of bytes written is returned, and the file position is updated in kind. On error, -1 is returned, and errno is set appropriately. A call to write( ) can return 0, but this return value does not have any special meaning; it simply implies that zero bytes were written.<br />As with read( ), the most basic usage is simple:<br /><br />const char *buf = "My ship is solid!";<br />ssize_t nr;<br />/* write the string in 'buf' to 'fd' */<br />nr = write (fd, buf, strlen (buf));<br />if (nr == -1)<br />/* error */<br /><br />But again, as with read( ) , this usage is not quite right. Callers also need to check for the possible occurrence of a partial write:<br /><br />unsigned long word = 1720;<br />size_t count;<br />ssize_t nr;<br />count = sizeof (word);<br />nr = write (fd, &word, count);<br />if (nr == -1)<br />/* error, check errno */<br />else if (nr != count)<br />/* possible error, but 'errno' not set */<br /> <br /><br /><b>Closing Files</b><br />After a program has finished working with a file descriptor, it can unmap the file descriptor from the associated file via the close( ) system call:<br /><br />#include <unistd.h><br />Int close (int fd);<br />A call to close( ) unmaps the open file descriptor fd, and disassociates the process from the file. The given file descriptor is then no longer valid, and the kernel is free to reuse it as the return value to a subsequent open( ) or creat( ) call. A call to close( ) returns 0 on success. On error, it returns -1, and sets errno appropriately. Usage is simple:<br /><br />if (close (fd) == -1)<br />perror ("close");<br /><br />Note that closing a file has no bearing on when the file is flushed to disk. If an application wants to ensure that the file is committed to disk before closing it, it needs to make use of one of the synchronization options discussed earlier in “Synchronized I/O.”<br />Closing a file does have some side effects, though. When the last open file descriptor referring to a file is closed, the data structure representing the file inside the kernel is freed. When this data structure is freed, it unpins the in-memory copy of the inode associated with the file. If nothing else is pinning the inode, it too may be freed from memory (it may stick around because the kernel caches inodes for performance reasons, but it need not). If a file has been unlinked from the disk, but was kept open before it was unlinked, it is not physically removed until it is closed and its inode is removed from memory. Therefore, calling close( ) may also result in an unlinked file finally being physically removed from the disk.<br /></div>Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com0tag:blogger.com,1999:blog-4224221485098744558.post-37301854414820278092012-03-19T19:23:00.000+05:302012-05-15T16:51:36.554+05:30Named Pipes: FIFOs<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-size: large;"><b>FIFO </b></span><br />
<br />
A named pipe is a special type of file (remember that everything in Linux is a file!) that exists as a name in the file system but behaves like the unnamed<br />
pipes that we’ve met already.<br />
<br />
We can create named pipes from the command line and from within a program. Historically, the command line program for creating them was mknod:<br />
<br />
$ mknod filename p<br />
<br />
However, the mknod command is not in the X/Open command list, so it may not be available on all UNIX-like systems. The preferred command line method is to use<br />
<br />
$ mkfifo filename<br />
<br />
Some older versions of UNIX only had the mknod command. X/Open Issue 4 Version 2 has the mknod function call, but not the command line program. Linux, friendly as ever, supplies both mknod and mkfifo.<br />
<br />
From inside a program, we can use two different calls:<br />
<br />
#include <sys/types.h><br />
#include <sys/stat.h><br />
int mkfifo(const char *filename, mode_t mode);<br />
int mknod(const char *filename, mode_t mode | S_IFIFO, (dev_t) 0);<br />
<br />
Like the mknod command, you can use the mknod function for making many special types of files. Using a dev_t value of 0 and ORing the file access mode with S_IFIFO is the only portable use of this function that creates a named pipe. We’ll use the simpler mkfifo function in our examples<br />
<br />
<br />
#include <unistd.h><br />
#include <stdlib.h><br />
#include <stdio.h><br />
#include <sys/types.h><br />
#include <sys/stat.h><br />
int main()<br />
{<br />
int res = mkfifo(“/tmp/my_fifo”, 0777);<br />
if (res == 0) printf(“FIFO created\n”);<br />
exit(EXIT_SUCCESS);<br />
}<br />
<br />
<br />
<br />
We can look for the pipe with<br />
<br />
$ ls -lF /tmp/my_fifo<br />
<br />
prwxr-xr-x 1 vineet embedyourcareer 0 march 18 14:55 /tmp/my_fifo|<br />
<br />
Notice that the first character of output is a p, indicating a pipe. The | symbol at the end is added by the ls command’s -F option and also indicates a pipe. <br />
<br />
<span style="font-size: large;"><b>How It Works</b></span><br />
<br />
The program uses the mkfifo function to create a special file. Although we ask for a mode of 0777, this is altered by the user mask (umask) setting (in this case 022), just as in normal file creation, so the resulting file has mode 755. If your umask is set differently, for example to 0002, you will see different permissions on the created file.<br />
We can remove the FIFO just like a conventional file by using the rm command, or from within a program by using the unlink system call.<br />
<br />
<br /></div>Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com0tag:blogger.com,1999:blog-4224221485098744558.post-55455648450663282672012-03-16T22:02:00.000+05:302012-05-15T16:51:36.630+05:30Basics of Inter process communication- PIPE<div dir="ltr" style="text-align: left;" trbidi="on">
<style type="text/css">
<!--
@page { margin: 0.79in }
P { margin-bottom: 0.08in }
-->
</style>
<br />
<div align="CENTER" style="font-weight: normal; margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: large;"> <i><b>Inter
Process Communication</b></i></span></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: medium;"><i><b>PIPE:</b></i></span></span></div>
<div style="font-weight: normal; margin-bottom: 0in;">
<br />
</div>
<div style="font-weight: normal; margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">We
use the term pipe when we connect a data flow from one process to
another. Generally we attach, or pipe, the output of one process to
the input of another.</span></span></div>
<div style="font-weight: normal; margin-bottom: 0in;">
<br />
</div>
<div style="font-weight: normal; margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">Most
Linux users will already be familiar with the idea of linking shell
commands together, so that the output of one process is fed straight
to the input of another. For shell commands, this is entered as</span></span></div>
<div style="font-weight: normal; margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;"> cmd1
| cmd2</span></span></div>
<div style="font-weight: normal; margin-bottom: 0in;">
<br />
</div>
<div style="font-weight: normal; margin-bottom: 0in;">
<br />
</div>
<div style="font-weight: normal; margin-bottom: 0in;">
<br />
</div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">The
shell arranges the standard input and output of the two commands, so
that</span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0in;">
❑ <span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">The
standard input to cmd1 comes from the terminal keyboard.</span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0in;">
❑ <span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">The
standard output from cmd1 is fed to cmd2 as its standard input.</span></span></div>
<div style="font-weight: normal; margin-bottom: 0in;">
❑ <span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">The
standard output from cmd2 is connected to the terminal screen.</span></span></div>
<div style="font-weight: normal; margin-bottom: 0in;">
<br />
</div>
<div style="font-weight: normal; margin-bottom: 0in;">
<br />
</div>
<div style="font-weight: normal; margin-bottom: 0in;">
<br />
</div>
<div style="font-weight: normal; margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">What
the shell has done, in effect, is reconnect the standard input and
output streams so that data flows from the keyboard input through the
two commands and is then output to the screen.</span></span></div>
<div style="font-weight: normal; margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;"><i><b>The
PIPE Call:</b></i></span></span></div>
<div style="font-weight: normal; margin-bottom: 0in;">
<br />
</div>
<div style="font-weight: normal; margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">The
pipe function has the following prototype:</span></span></div>
<div style="font-weight: normal; margin-bottom: 0in;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">#include
<unistd.h></span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">int
pipe(int file_descriptor[2]);</span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">pipe
is passed (a pointer to) an array of two integer file descriptors. It
fills the array with two new file descriptors and returns a zero. On
failure, it returns -1 and sets errno to indicate the reason for
failure. Errors defined in the Linux manual page (section 2 of the
manual) are</span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0in;">
❑ <span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">EMFILE:
Too many file descriptors are in use by the process.</span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
❑ <span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">ENFILE:
The system file table is full.</span></span></div>
<div style="margin-bottom: 0in;">
❑ <span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">EFAULT:
The file descriptor is not valid.</span></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">The
two file descriptors returned are connected in a special way. Any
data written to file_descriptor[1] can be read back from
file_descriptor[0]. The data is processed in a first in, first out
basis, usually abbreviated to FIFO. This means that if you write the
bytes 1, 2, 3 to file_descriptor[1], reading from file_descriptor[0]
will produce 1, 2, 3. This is different from a stack, which operates
on a last in, first out basis, usually abbreviated to LIFO.</span></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">Here’s
a program, pipe1.c, that uses pipe to create a pipe.</span></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;"><i><b>Type
the following code. </b></i></span></span>
</div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">Note
the file_pipes pointer, which is passed to the pipe function as a
parameter.</span></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">#include
<unistd.h></span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">#include
<stdlib.h></span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">#include
<stdio.h></span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">#include
<string.h></span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">int
main()</span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">{</span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;"> int
data_processed;</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;"> int
file_pipes[2];</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;"> const
char some_data[] = “123”;</span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;"> char
buffer[BUFSIZ + 1];</span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;"> memset(buffer,
‘\0’, sizeof(buffer));</span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;"> if
(pipe(file_pipes) == 0)</span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;"> { </span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;"> data_processed
= write(file_pipes[1], some_data, strlen(some_data));</span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;"> printf(“Wrote
%d bytes\n”, data_processed);</span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;"> data_processed
= read(file_pipes[0], buffer, BUFSIZ);</span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;"> printf(“Read
%d bytes: %s\n”, data_processed, buffer);</span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;"> </span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;"> exit(EXIT_SUCCESS);</span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;"> }</span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;"> exit(EXIT_FAILURE);</span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">}</span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0in;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">When
we run this program, the output is</span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">$
./pipe1</span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">Wrote
3 bytes</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">Read
3 bytes: 123</span></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: medium;"><b>How
It Works</b></span></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">The
program creates a pipe using the two file descriptors file_pipes. It
then writes data into the pipe using the file descriptor file_pipes
and reads it back from file_pipes. Notice that the pipe has some
internal buffering that stores the data in between the calls to write
and read. </span></span>
</div>
<div align="LEFT" style="margin-bottom: 0in;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">You
should be aware that the effect of trying to write using
file_descriptor, or read using file_descriptor, is undefined, so the
behavior could be very strange and may change without warning. On the
authors’ systems, such calls fail with a –1 return value, which
at least ensures that it’s easy to catch this mistake.</span></span></div>
<div align="LEFT" style="margin-bottom: 0in;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0in;">
<span style="font-family: Tahoma,sans-serif;"><span style="font-size: small;">At
first glance, this example of a pipe doesn’t seem to offer us
anything that we couldn’t have done with a simple file. The real
advantage of pipes comes when you wish to pass data between two
processes. </span></span>
</div>
<div align="LEFT" style="margin-bottom: 0in;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0in;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0in;">
<br />
</div>
</div>Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com0tag:blogger.com,1999:blog-4224221485098744558.post-48348726521134630442012-02-13T00:06:00.001+05:302012-05-15T16:51:36.599+05:30Innovations in Autonomous Robot Technology: Are Flying Robots the Future of Construction?<div dir="ltr" style="text-align: left;" trbidi="on">
<span class="lblBigTextRestText" id="lblRestText"></span><br />
Two recent demonstrations of autonomous quadrotor helicopter technology
have sparked renewed interest in the potential for using automated
robotics for construction and search and rescue operations.
<br />
<br />
<br />
In early December last year, ETH Zurich roboticist Raffaello D'Andrea
and architects Fabio Gramazio and Matthias Kohler, also from ETH,
created an art installation titled 'Flight Assembled Architecture' just
outside of Paris.
<br />
The installation used a series of miniature quadrotor helicopters to autonomously build a six metre tower from Styrofoam blocks.
<br />
Four robots worked on the project at any one time, relying on detailed
blueprints and a motion capture system embedded in the roof to
accurately construct the tower at a rate of 100 blocks per hour.<br />
<br />
<span class="lblBigTextRestText" id="lblRestText"></span><br />
On the other side of the pond, a research team at the University of
Pennsylvania's General Robotics, Automation, Sensing and Perception
(GRASP) Lab recently uploaded a video to Youtube demonstrating their
advancements in so-called 'swarm' technology.
<br />
The video shows twenty miniature quadrotors performing complex
manoeuvres, navigating around obstacles and otherwise demonstrating what
the team describes as "complex autonomous swarm behaviour."
<br />
While the technology demonstrated by these two teams is far from market ready, its potential applications are intriguing.
<br />
<br />
Larger versions of the building robots, for example, could potentially
be used in the construction industry to erect buildings faster and more
efficiently, while significantly reducing the occupational health and
safety risks for associated workers.<br />
<br />
<br />
While GRASP's demonstration has raised some concerns as to the use of
similar technology for unauthorised surveillance operations, the ability
of the quadrotors used in their experiment to successfully navigate
obstacles points to some very useful potential applications in the area
of search and rescue.
<br />
<br />
For example, rescue workers could potentially use a similar system to
explore high risk areas, and to gain access to enclosed spaces that are
too small for a human being to explore.
<br />
With the development of such advanced autonomous technology inevitably
comes moral and ethical concerns over its use, but if utilised in the
right way, self-guiding robots could be used in a variety of
applications to complete tasks more efficiently, and importantly, with
far less risk for human workers.
<br />
<br />
<br />
source: Internet</div>Mr Vinshttp://www.blogger.com/profile/12334989404374907418noreply@blogger.com0