Linuxjournal 163
Linuxjournal 163
LINUX JOURNAL
™
High-Performance
Network Programming
SCTP Multiple Associations
HIGH-PERFORMANCE COMPUTING
+
THE PRESENT
AND FUTURE
KING OF HPC
INTERVIEW WITH
RapidMind
HIGH-PERFORMANCE
COMPUTING
NOVEMBER 2007 ISSUE 163
GEOINT
San Antonio, TX - Booth 374
Oct. 22 - 24
Super Computing
Reno, NV - Booth 164
Nov. 12 - 15
LISA
Dallas, TX - Booth 200
Nov. 14 - 15
DaCEY Awards
Atlanta, GA
Nov. 15
Interface Seattle
Seattle, WA - Booth 206
Nov. 28
Avocent builds hardware and software to access, manage and control any IT asset in
your data center, online or offline, keeping it, and your business, “always on”.
HIGH-PERFORMANCE
COMPUTING
IMAGE ©ISTOCKPHOTO.COM/NARVIKK
FEATURES
46 RED HAT ENTERPRISE LINUX CLUSTER SUITE 60 DISTRIBUTED COMPUTING WITH DISTCC
The trusty Red Hat cluster. Put your lazy machines to work.
Khurram Shiraz Jes Hall
2 | november 2007 w w w. l i n u x j o u r n a l . c o m
Agility.
With Coyote Point, you'll never have to wonder if your
network is fast enough or flexible enough. You'll know it is.
From local to global load balancing, application
acceleration or ultimate network manageability, Coyote
Point leads the pack. We take the guesswork and difficulty
out of application traffic management. You won’t find
anything faster, smarter or more affordable.
Find out why more than 2,000 businesses rely on us to
maximize their infrastructure. Learn what Coyote Point
could mean to your Web and network traffic.
Write [email protected] or call 1-877-367-2696.
74 MULTIPLE ASSOCIATIONS
WITH STREAM CONTROL
TRANSMISSION PROTOCOL
Chat up SCTP.
Jan Newmarch
USPS LINUX JOURNAL (ISSN 1075-3583) is published monthly by Belltown Media, Inc., 2211 Norfolk, Ste 514, Houston, TX
77098 USA. Periodicals postage paid at Houston, Texas and at additional mailing offices. Cover price is $5.99 US. Subscription rate is
$25/year in the United States, $32 in Canada and Mexico, $62 elsewhere. POSTMASTER: Please send address changes to Linux
Journal, PO Box 980985, Houston, TX 77098. Subscriptions start with the next issue.
4 | november 2007 w w w. l i n u x j o u r n a l . c o m
..;174%14'5#4'$'.10)6175T
&RUHVVWDUWLQJDW
T
'48'422.+#0%'5
LNNTMGGTKIEN
462/&20,1&$OOULJKWVUHVHUYHGDOOWUDGHPDUNVDUHWKHSURSHUW\RIWKHLUUHVSHFWLYHFRPSDQLHV
Editor in Chief
Nick Petreley, [email protected]
GO SOLID.
Senior Editor Doc Searls
[email protected]
Art Director Garrick Antikajian
INCREASE RELIABILTY.
[email protected]
Products Editor James Gray
[email protected]
Editor Emeritus Don Marti
[email protected]
Technical Editor Michael Baxter
[email protected]
Senior Columnist Reuven Lerner
[email protected]
Chef Français Marcel Gagné
[email protected]
Security Editor Mick Bauer
[email protected]
Contributing Editors
David A. Bandel • Ibrahim Haddad • Robert Love • Zack Brown • Dave Phillips
Marco Fioretti • Ludovic Marcotte • Paul Barry • Paul McKenney • Dave Taylor
Direct-Plug Linux Journal is published by, and is a registered trade name of, Belltown Media, Inc.
PO Box 980985, Houston, TX 77098 USA
IDE Flash Modules
Editorial Advisory Board
Daniel Frye, Director, IBM Linux Technology Center
Intel, VIA & AMD CPUs Jon “maddog” Hall, President, Linux International
Lawrence Lessig, Professor of Law, Stanford University
Ransom Love, Director of Strategic Relationships, Family and Church History Department,
Church of Jesus Christ of Latter-day Saints
(IÀFLHQF\5DWHG Sam Ockman
Bruce Perens
PicoPSU Power Supplies Bdale Garbee, Linux CTO, HP
Danese Cooper, Open Source Diva, Intel Corporation
Advertising
E-MAIL: [email protected]
URL: www.linuxjournal.com/advertising
DISCOVER MINI-ITX. PHONE: +1 713-344-1956 ext. 2
Subscriptions
E-MAIL: [email protected]
URL: www.linuxjournal.com/subscribe
PHONE: +1 713-589-3503
FAX: +1 713-589-2677
TOLL-FREE: 1-888-66-LINUX
MAIL: PO Box 980985, Houston, TX 77098 USA
Please allow 4–6 weeks for processing address changes and orders
PRINTED IN USA
www.logicsupply.com
letters
years use more power and produce more waste forbids consumers to copy and give away
heat. Even a PIII might have cooling problems! music media. Their morality is based on laws
that were manufactured by a Congress eager
One thing that is not widely known is that a to be bribed. It’s easy to burst the RIAA’s
P4 will generally take more clock cycles than moral bubble. Just travel back to 1850 in
a PIII to complete a given amount of work— your mind and go hear a music performer.
a 1.5GHz P4 will often deliver the same
performance as a 1GHz PIII! If a machine In 19th-century America, the artists played and
is to run in a poorly ventilated space, a the people enjoyed. It had been that way for
PIII is a significantly better option than a P4. 10,000 years. If the artists were lucky or very
good, they could make a living by performing.
Hard drives take as much as 5W when Many do that to this very day. It is an honest liv-
idling. Use of other mass storage devices ing. They work at what they love. It’s their job.
(such as USB) might reduce the power use
for such a machine. It was a temporary quirk of technology that
allowed artists and record companies to turn
I have a small stockpile of old PIII machines for performances into commodities to be bought
occasions when I need a low-power machine. and sold. A few lucky artists could perform,
-- record and then sit back and let the bucks roll in
Your Wish Is Our Command Russell Coker while they snorted coke and bought mansions.
I would love to see a detailed explanation on That’s OK with me, and it still works for some.
the new Completely Fair Scheduler in the The Inevitable Descent into Anarchy But, the data is written on the wall, and it is an
Linux kernel, including areas where it may be The Linux OS is the most glamorous (I’m age-old warning that applies to all: adapt or die.
inferior to the existing scheduler and where it serious) example of [the] trend [toward data
excels. Also, I’d like to see an explanation of anarchy], but Linux is only an outgrowth of a Readers may wonder what all this has to do
the tickless patches, which apparently result much bigger universe of collaborative software with cell-phone networks. Carl Brown suggest-
in significant power savings. development that uses open-source licenses ed that there is nothing fundamentally block-
-- and techniques to leverage the talents and ing the concept of a user-created cell-phone
Chris Thompson creative impulses of hundreds of thousands network. It also is true that there is nothing
of people worldwide. Cheap MP3 players blocking users from building their own world-
We’ll look into a scheduling article, but we have and P2P file-sharing networks are another. wide data network, uncontrolled by govern-
an article on power savings in the works, includ- ments or corporations. If I can share my Wi-Fi
ing information on the tickless patches.—Ed. Direct evidence of the trend is plummeting CD with the neighbors in my apartment, I can
sales as users swap CDs, copy new ones, file bridge to the guy across the street who can
The Arcade Game Machine Is Hot! share and port their files to any device they run a directional shot to his buddy a quarter-
I was very interested to read Shawn Powers’ want. The efforts of the RIAA are becoming mile away who can...(ad infinitum).
article on building an arcade machine based laughable, as they sue a few unfortunates and
around Linux [LJ, August 2007]. However, one scold the rest of the population from a position The idea was not invented by me, although I
thing that concerns me is the lack of reference of pious hypocrisy. They are the biggest thieves humbly declare I thought of it myself. The idea
to cooling issues. If a PC is in a wooden box for of all. Also pathetic are the many pop stars, now is so obvious, anyone with an understanding of
any period of time without a fan to force cool grown rich and fat sucking on the corporate tit, networks is likely to conceive of it. A quick
air through, there would be a risk of heat dam- who parrot the RIAA’s line. It matters not. Google search brings to light that user-operated
age to the machine, particularly the CPU and and user-supported community networks are
the hard drive (www.coker.com.au/energy/ The only reason artists and record companies already providing free service to many people.
computer-power.html). ever had control over music media was that The ISPs don’t like it, but there’s nothing they
it was impractical for listeners to create their can do about it. Those simple networks, howev-
The above URL has the energy use of some own. Given that ability, most listeners will er, are only attachments to the Internet. They
computers I have owned at various times (the follow my own common-sense creed: when still depend on the corporate infrastructure.
idle tests were idle at a Linux prompt—idle at a I get the data, it’s my data, and I’ll do with
DOS prompt or the BIOS uses significantly more it what I damn well please. Another and related sign of the trend toward
power). You will note that a P4 machine uses anarchy is revealed in the project called
significantly more power than a PIII. I can only The RIAA hands down morality lessons while Netsukuku (netsukuku.freaknet.org). That
guess at the relative power requirements of a cracking the lawsuit whip in hope of putting project community has created a dæmon
PIII and the original game hardware, but I the file-sharing genie back in its bottle. They that uses network interfaces to communicate
expect that all PCs manufactured in the last ten pretend that there is some moral code that directly with the same dæmon in a connected
8 | november 2007 w w w. l i n u x j o u r n a l . c o m
GO STRAIGHT TO THE SOURCE!
MORE PRODUCTS, BETTER SERVICE, GUARANTEED.
SDR-1105T 1U ENTRY LEVEL SERVER EXCELLENT GENERAL PURPOSE SERVER FOR ORGANIZATIONS WITH THE NEED
FOR A LOW, ENTRY LEVEL PRICE
* 1U Rackmount Chassis with 520W power supply
* Supermicro X7DVL-L Server Board with Intel® 5000V (Blackford VS) Chipset
* Intel Quad-Core Xeon Processor E5310 1.6GHZ
* Total 512MB, 2pcs x 256MB Kingston DDR2 533Mhz FB-DIMM ECC
* Seagate SATAII 160GB 7200 RPM 8MB Cache SATA 3.0Gb/s Hard Drive
$1,129
* 4 x 1” Hot-swap SATA Drive Bays
* Two Intel® 82563EB Dual-port Gigabit Ethernet Controller
* Intel® ESB2 SATA 3.0Gbps Controller RAID 0, 1, 5, 10 support
$1,259
* Intel Quad-Core Xeon Processor E5310 1.6GHZ * Intel® (ESB2/Gilgal) 82563EB Dual-port Gigabit Ethernet Controller
STARTING
* Total 512MB, 2pcs x 256MB Kingston DDR2 533Mhz FB-DIMM ECC * Intel® ESB2 SATA 3.0Gbps Controller RAID 0, 1, 5, 10 support
PRICE
----------------------------------------------------------------------- ----------------------------------
SDR-3500T 3U DATABASE SERVER
Easily Scalable storage solution with hot-swap functionality for growing businesses
* 3U Rackmount chassis with Redundant 800W power supply * Seagate SATAII 500GB 7200 RPM 16MB Cache SATA 3.0Gb/s
* Supermicro X7DBE+ Server Board with Intel® 5000P (Blackford) Hard
Chipset Drive
* Intel Quad-Core Xeon Processor E5310 1.6GHZ * 16 x 1" Hot-swap SATA Drive Bays
* Total 1024MB, 2pcs x 512MB Kingston DDR2 533MHz FB-DIMM * Dual-port Gigabit Ethernet Controller
STARTING
PRICE $1,999 ECC
----------------------------------------------------------------------- ----------------------------------
* Intel ESB2 SATA 3.0Gbps Controller RAID 0, 1, 10 support
----------------------------------------------------------------------- ----------------------------------
SDR-5111T 5U ADVANCED STORAGE SERVER
Quad Core dual Xeon CPU based, with 24 hot-swap hard disk bays suitable for 18TB of pure data Storage
capacity
* 5U Rackmount chassis with Redundant 1350W power supply * Seagate 750GB 7200 RPM 16MB Cache SATA 3.0Gb/s Hard Drive
* Supermicro X7DBE Server Board with Intel® 5000P (Blackford) * 24 x 1" Hot-swap Drive Bays
Chipset * Intel® (ESB2/Gilgal) 82563EB Dual-
* Intel Quad-Core Xeon Processor E5310 1.6GHZ port Gigabit Ethernet Controller
STARTING
$3,099
* Total 1024MB, 2pcs x 512MB Kingston DDR2 667MHz FB- * Intel ESB2 SATA 3.0Gbps Controller
PRICE DIMM ECC RAID 0, 1, 5, 10 support
SERVERS DIRECT CAN HELP YOU CONFIGURE YOUR NEXT HIGH PERFORMANCE SERVER SYSTEM - CALL US TODAY!
Our flexible on-line products configurator allows you to source a custom solution, or call and our product experts are standing by to
help you assemble systems that require a little extra. Servers Direct - your direct source for scalable, cost effective server solutions.
1.877.727.7887 | www.ServersDirect.com
Intel, Intel logo, Intel Inside, Intel Inside logo, Intel Centrino, Intel Centrino logo, Celeron, Intel Xeon, Intel SpeedStep, Itanium, Pentium, and Pentium III Xeon are trademarks of
Intel Corporation or it’s subsidiaries in the United States and other countries.
[ LETTERS ]
computer. In theory, the mesh network so The Ultimate Linux Box had nothing to
created can mimic the Internet’s TCP/IP do with Windows games or serving up
layer with a decentralized domain name DirectX 10, which isn’t even very useful on
system that uses distributed architecture Windows yet. We’ll consider your desires
and builds routes that connect the for the next ULB issue though.—Ed.
computers attached to its network. It
is, as the creators say, anarchical. Protection Money
At Your Service
I have to congratulate you on your
I do not claim to see the future. I only /var/opinion “The Benevolent Racketeer”
extrapolate what seems to be an inex- [LJ, August 2007]. MAGAZINE
orable transfer of communications and
PRINT SUBSCRIPTIONS: Renewing your
data management power from the elite to Your imaginary letter writer speaks right subscription, changing your address, paying your
the masses. If you believe in people, this out of the soul of everybody. The crowd invoice, viewing your account details or other
can only be a good thing. If you fear peo- reading the lines will equally agree and subscription inquiries can instantly be done on-line,
ple, or begrudge them control over their see their points addressed as the crowd www.linuxjournal.com/subs. Alternatively,
within the U.S. and Canada, you may call
own lives, then you will fight it...and lose. reading between the lines. Luckily, I
us toll-free 1-888-66-LINUX (54689), or
-- paid my insurance money to Linux internationally +1-713-589-2677. E-mail us at
Tim Copeland Journal, so you will not sue me for [email protected] or reach us via postal mail,
reading this terrific piece of word code. Linux Journal, PO Box 980985, Houston, TX
Practical Linux Box 77098-0985 USA. Please remember to include your
-- complete name and address when contacting us.
I eagerly awaited the current issue of LJ Kurt
[September 2007] to read the Ultimate DIGITAL SUBSCRIPTIONS: Digital subscriptions
Linux Box article. I plan to build a system mkdir Errors of Linux Journal are now available and delivered as
PDFs anywhere in the world for one low cost.
very soon and hoped to get some ideas. I too have a small nit to pick with
Visit www.linuxjournal.com/digital for more
respect to sample code and the lack of information or use the contact information above
Unfortunately, I just skimmed the article and error handling. It is trivial to add at least for any digital magazine customer service inquiries.
was very disappointed. What I really would some minimal error handling. In the
LETTERS TO THE EDITOR: We welcome
like to see is a Practical Linux Box. No, your September 2007 issue’s Letters, Jack your letters and encourage you to submit them
sidebar “Penultimate” doesn’t address my points out that mkdir error handling is to [email protected] or mail them to
needs any more than the ULB. Your ULB is non-existent. Bash scripts are notorious Linux Journal, 1752 NW Market Street, #200,
really the Ultimate [Windows] Gaming Box, for not doing any error handling. As Seattle, WA 98107 USA. Letters may be edited
for space and clarity.
isn’t it? For example, look at the Display Card for the mkdir issue that Jack points out,
section. It’s the latest and greatest DirectX 10 I would suggest the following: WRITING FOR US: We always are looking
card? How is this a good Linux box? for contributed articles, tutorials and real-
mkdir -p $dimension world stories for the magazine. An author’s
guide, a list of topics and due dates can be
The things I’m looking for may not be if [ $? -ne 0 ]; then
found on-line, www.linuxjournal.com/author.
what everyone else is looking for, but I’d echo "Error: could not create\
like to think there are enough people to directory $dimension" ADVERTISING: Linux Journal is a great
resource for readers and advertisers alike.
warrant some practical thinking in this return 1
Request a media kit, view our current
type of article, such as: fi editorial calendar and advertising due
dates, or learn more about other advertising
I Quiet/fanless power supply and case. The -p switch to mkdir will create all and marketing opportunities by visiting us
directories in the $dimension string on-line, www.linuxjournal.com/advertising.
Contact us directly for further information,
I Small case with enough room for DVD recursively and will not complain if any [email protected] or +1 713-344-1956 ext. 2.
and two hard drives. or all directories already exist. The main
reason for failure will be user permis-
I Affordable: $2,000–$4,000 is not prac- sions. This is handled by echoing the
tical or affordable. error and returning an error value to ON-LINE
the caller. WEB SITE: Read exclusive on-line-only content on
I Onboard video is ok. Linux Journal’s Web site, www.linuxjournal.com.
If the goal of these sample scripts is to Also, select articles from the print magazine
You could argue that I want a media PC, instruct beginners to learn techniques are available on-line. Magazine subscribers,
digital or print, receive full access to issue
but that’s not really my goal. I’d settle for with bash, error handling cannot be archives; please contact Customer Service for
one. I’m estimating that I can build a sys- ignored. The same goes for Ruby, further information, [email protected].
tem that fits the above specs for about Python, Perl, C and C++. The code
FREE e-NEWSLETTERS: Each week, Linux
$700, without monitor. Other names for samples in the SCTP (why does that
Journal editors will tell you what's hot in the world
what I want might be the Quiet Linux Box make me think of John Candy) article of Linux. Receive late-breaking news, technical tips
or the Affordable Linux Box. are excellent in this regard. and tricks, and links to in-depth stories featured
on www.linuxjournal.com. Subscribe for free
-- --
today, www.linuxjournal.com/enewsletters.
JT Moree steeve
10 | november 2007 w w w. l i n u x j o u r n a l . c o m
UPFRONT NEWS + FUN
LJ Index,
November 2007
1. Average measured speed in MBps of a
broadband connection with “up to 8Mbps”
download speed: 2.7
Linus Torvalds mailing list tend to assume—for
diff -u has expressed keen
interest in finding
example, how to do a binary search
with git to identify precisely when
2. Lowest measured speed in KBps of a
broadband connection with “up to 8Mbps”
WHAT’S NEW someone to put a particular bug was introduced into download speed: 90
IN KERNEL together a full git the tree.
3. Number of consumers out of five who get
DEVELOPMENT repository of the Several projects have changed
the broadband speed they signed up for: 1
kernel, going all hands recently. Valerie Henson has
the way back to version 0.01. He’s had to abandon the Tulip driver, and 4. Percent of surveyed consumers who have
tried this himself a couple times, and now it looks like Kyle McMartin may felt misled by providers’ advertising: 30
other folks have made various efforts, become the official maintainer. Wim
but it’s a hard problem. Certainly, it Van Sebroeck has submitted a patch 5. Billions of Internet users in 2006: 1.1
would not be possible to include every to make Mike Frysinger the official
6. Additional millions of Internet users expected
patch that went into the kernel, in the maintainer of the Blackfin Watchdog
by 2010: 500
order it was included, because many driver. Mike Sharkey of Pike
patches never were sent to any public Aerospace Research Corporation 7. Millions of video streams per day served by
forum. Even finding the release has volunteered to take over the YouTube: 100
announcements for all the numbered otherwise unmaintained Parallel Port
versions will be difficult, and some driver on behalf of his company. 8. Number of surveillance cameras in London: 200
official releases are thought to be lost And, Anton Vorontsov recently
9. Trillions of bits sent by London surveillance
as well. It’s a daunting task, but a very became a co-maintainer of the cameras to their data center: 64
valuable one, even if done incompletely. Power Supply subsystem, along
If someone can do it, Linus has offered with David Woodhouse. 10. Terabytes accumulated per day by Chevron: 2
to comment the various early patches Over time, various features have
and releases, from memory. gone into the kernel to support more 11. Total exabytes of data in 2006: 161
Mingming Cao has submitted and more modern architectures. But, for
12. Multiple in millions of 2006 data total to
patches to allow the ext4 filesystem some of these features that have no seri- all information in all books ever written: 3
to perform checksum calculations on ous negative impact on older hardware,
its journal to make sure that any cor- such as the 386 processor, there’s been 13. Percentage of the digital universe that will
ruption is identified as quickly as possi- no real effort to isolate the unneeded be created by individuals by 2010: 70
ble. With interest from various folks, features from that older hardware.
including Andrew Morton, it looks Kernels compiled for those systems, 14. Percentage of the current digital universe
that is subject to compliance rules and
like this feature quickly will be adopted therefore, have tended to have larger
standards: 20
into the official tree, although ext4 still and larger binaries and to require more
remains a fairly experimental filesystem. and more RAM to run. For the most 15. Percentage of the current digital universe
LinuxConf Europe 2007 (LCE) will part, no one notices or cares, because that is potentially subject to security
host a semi-formal discussion of con- most people don’t bother running Linux applications: 30
tainers within the kernel. Serge E. on the 386 anymore. But, the effect has
16. Exabytes of “user-generated content”
Hallyn recently announced plans to been there, building gradually.
expected by 2010: 692
arrange for a conference room (includ- Jonathan Campbell recently
ing phone lines for anyone who can’t started submitting patches to ensure 17. Total exabytes of data expected by 2010: 988
be present but still wants to partici- that architectures like the 386 would
pate) and a series of half-hour presen- compile only features that actually 18. Percentage of the 2010 digital universe for
tations. Containers provide a way to would work on those systems. So, which organizations will be responsible for
security, privacy, reliability and compliance: 85
cluster processes into specific name- things like the Pentium TSC register
spaces that are isolated from the rest would not be included in compiled 19. Exabyte capacity of media ready to store
of the system and are related to 386 kernel binaries. The result of his newly created and replicated data in the
virtualization projects like Xen. work was a much smaller binary, and 2010 digital universe: 601
Michal Piotrowski has announced his patches probably will be adopted
the “Linux Kernel Tester’s Guide”, into the main kernel tree. This kind of 20. Year in which the amount of information
translated by Rafael J. Wysocki, at support for legacy systems might have created will surpass available storage
capacity for the first time: 2007
www.stardust.webpages.pl/files/ an impact on projects to bring com-
handbook/handbook-en-0.3-rc1.pdf. puting resources to third-world coun- Sources: 1, 2: which.co.uk, sourced by David
It is a long document representing tries and impoverished neighborhoods Meyer for ZDNet UK | 3, 4: moneysupermarket.com,
much work, it reads like a book, and or lower the cost of experimenting sourced by David Meyer for ZDNet UK | 5–20:
it clearly explains a lot of material that with clustered solutions. “Expanding the Digital Universe”, by John F.
most discussions on the linux-kernel —ZACK BROWN Gantz, et al., a March 2007 IDC whitepaper
12 | november 2007 w w w. l i n u x j o u r n a l . c o m
[ UPFRONT ]
They Said It
If our customers buy bandwidth from us, and they want to share it with
neighbors, or publicly, that doesn't make them bad customers.
—Joe Plotkin, Bway.net, www.businessweek.com/technology/content/jul2002/
tc2002073_1130.htm
...the commercial concerns from the very beginning, even when they were small,
were really very important. The commercial distributions were what drove a lot
of the nice installers, and pushed people to improve usability....I think commer-
cial users of Linux have been very important in actually improving the product.
I think all the technical people who have been involved have been hugely
important, but I think that the kind of commercial use that you can get with the
GPLv2 is also important—you need a balance between pure technology, and the
kinds of pressures you get from users through the market....If you have a purely
marketing (or customer) driven approach, you end up with crap technology in
the end. But I think that something that is purely driven by technical people will
also end up as crap technology in the end, and you really need a balance here.
—Linus Torvalds, www.linuxworld.com/news/2007/
080907-torvalds-on-linux-ms-softwares.html?page=2
It's exciting to go to work each day knowing that scads of companies are using
your software, then contacting you to get additional value. It's not easy by any
stretch, but it's a lot more efficient and productive than the proprietary model.
—Matt Asay, blogs.cnet.com/
8301-13505_1-9762210-16.html?part=rss&tag=feed&subj=TheOpenRoad
"SFZPV
4IPDLFE
CZUIF
IJHIDPTU
PGJ4$4*
'JCSF$IBOOFM
4"/TUPSBHF
"P&JTUIFBOTXFS
"5"PWFS&UIFSOFU'BTU
3FMJBCMF
4JNQMFTUPSBHF
XXXDPSBJEDPN
'BTU(JHBCJU&UIFSOFU4UPSBHF
XJUIPVUUIF5$1*1PWFSIFBE
6OMJNJUFEFYQBOEBCJMJUZ
BUUIF
MPXFTUQPTTJCMFQSJDFQPJOU
¥ :PVXBOUNPSFTUPSBHFyZPV
&UIFS%SJWF 43YYYY
KVTUCVZNPSFEJTLToJUTUIBU
r'BTU'MFYJCMF3"*%BQQMJBODFT TJNQMF
XJUITMPUTGPSIPUTXBQ4"5"EJTLT
¥
r$IFDLPVUPVSGVMMMJOFPG&UIFS%SJWF 4UPSBHFBOE 7JTJUVTBUXXXDPSBJEDPN
7JSUVBM4UPSBHF"QQMJBODFTBOE/"4(BUFXBZT
XXXDPSBJEDPN
TECH TIPS
Display date and time in the past or future and pop through directories easily.
UU Show Date or Time, Past or Future I -f format: Display the date and time according to formatting
When working on Linux/UNIX platforms, I frequently find it useful directives specified in format.
to obtain the date and time in the past or future. Whether
scheduling jobs, searching for files from a certain date or deter- Options e and f are incompatible. Specifying them together
mining the day on which a certain date falls, countless scenarios on the command line terminates the program abnormally. The
need a routine to compute and display the date and time in the default output of showdate can be tweaked with the formatting
past or future. I searched for a suitable program, but ultimately directives and argument to -f, which are identical to the ones
had to write one myself. This program is called showdate. It is used by the standard date command. The important thing is that
written in the C language originally on UNIX and has been ported all computations are performed by taking either a positive (future)
over to Linux as well. You can download the code from the LJ FTP or negative (past) offset from the current date and time (now),
site: ftp.linuxjournal.com/pub/lj/listings/issue163/9877.tgz. which is its datum.
After obtaining the source code, assemble the showdate A good way to become familiar with any tool quickly is to under-
executable using an ANSI C compiler (either cc or gcc) as shown: stand how it is used. For example, the command to display the date
and time ten years ago, relative to now, would be (output of showdate
# cc showdate.c -o showdate has been omitted as the results depend on the value of now):
I -y [+|-]years: Number of years in the past (-) or future (+) offset The options can appear in any order, as long as their contextual
from the current year. usage is unambiguous; therefore, the command line above could be
written as:
I -m [+|-]months: Number of months in the past (-) or future (+)
offset from the current month. # showdate -m 2 -f %Y-%m-%d -d 23 -y 5
I -d [+|-]days: Number of days in the past (-) or future (+) offset from The +- offsets can be combined in a single command line; howev-
the current day. er, mixing them up can lead to unexpected and erroneous results. If
now is January 1st 2003 12:00:00 AM UTC, showdate outputs:
I -h [+|-]hours: Number of hours in the past (-) or future (+) offset
from the current hour. # showdate -m -8 -M 32
Wed May 1 00:32:00 2002
I -M [+|-]minutes: Number of minutes in the past (-) or future (+)
offset from the current minute. The above command displays the date and time in the past—
eight months ago but 32 minutes from now, while the one below
I -s [+|-]seconds: Number of seconds in the past (-) or future (+) displays the date and time in the future—8 months from now but
offset from the current second. 32 minutes ago:
I -e: Display the time elapsed in seconds since the UNIX epoch # showdate -m 8 -m -32
(January 1, 1970 UTC). Sun Aug 31 23:28:00 2003
18 | november 2007 w w w. l i n u x j o u r n a l . c o m
TECH TIPS
The current date and time is tracked as the number of seconds $ popd
that have elapsed since the epoch. This number is stored in a signed
long, which means that on a 32-bit system, the timekeeping will break The above command removes the topmost directory entry
on Tuesday January 19, 2038 at 03:14:08 UTC, when the value over- (/home/sangeeth/soft/release2/src/) and performs a cd to the new
flows and becomes negative. An error is returned if the desired date top directory, which in my case, will be the second directory
and time exceeds this limit as shown here: (/home/sangeeth/soft/release2/src/show/).
Alternatively, one can pop a particular directory from the list of
# showdate -y 1000 directories by giving the directory ID (the ID is displayed beside a
showdate: required time exceeds system limit directory when using dirs -l -p -d) to the popd command:
I /home/sangeeth/soft/release2/src/
I /home/sangeeth/soft/release2/src/show/
I /home/sangeeth/soft/release2/doc/
$ pushd /home/sangeeth/soft/release2/src/
$ pushd /home/sangeeth/soft/release2/src/show/
$ pushd /home/sangeeth/soft/release2/doc/
w w w. l i n u x j o u r n a l . c o m november 2007 | 19
COLUMNS
AT THE FORGE
REUVEN M. LERNER People are surprising and unpredictable. In the computer increasingly standard part of Web-based applications, but
industry, you hear this in nearly every interview with the despite everyone’s use of the term API, that acronym
designer of a popular software package. For example, Perl means different things to different people.
originally was designed for network programming and text Starting next month, I’m going to look at the latest
processing. This made it an obvious choice for Web pro- batch of APIs that sites such as Facebook are offering. But
gramming, but Larry Wall certainly didn’t know or expect this month, I want to take a step back and consider the
that when he first wrote the language, years before the different types of APIs that software publishers offer. This
Web was invented. is useful if you intend to extend, use and work with those
Users of a software package almost always will push APIs. Web development is increasingly a matter of tying
its limits. That’s why some of the most successful and together existing functionality from other sites, and
popular programs are those that encourage users to go understanding these APIs can be quite useful.
beyond the author’s imagination. In the early days of the It’s also important for Web developers to understand
software industry, such add-ons and plugins didn’t exist, the nature of APIs. If you want to create the next
which meant that the only way to get new functionality Facebook or Google, you’re going to need to create more
was to lobby the authors and then hope the next release than a winning product. You’re going to need an ecosys-
would include the needed features. In the world of open- tem of developers and third-party software around your
source software, anyone is theoretically able to add new core product. One of the best ways to do this is to create
features, but between the generally small number of core and promote APIs, letting people use your application as
developers and the famously loud debates that sometimes a platform, rather than a standalone program. By looking
erupt, it can take surprisingly long to add a new feature. around and seeing what others have done, we can get a
(And although it is always possible to fork a project, this better sense of just what the possibilities are and how
has social and technical drawbacks that often outweigh we might use them.
the benefits.)
Some programs have a long tradition of encouraging Read-Only Protocols
add-ons. GNU Emacs is best known as a text editor, but it In the beginning, when Tim Berners-Lee invented the
comes with a full-fledged version of the Lisp programming Web, he imagined it as a read-write medium. But for
language. You can create just about anything you want in most people who used the Web during the first decade,
Emacs, and people have done so, including mail-reading it was a read-only medium. You could view Web sites with
programs, Web browsers and an extremely sophisticated your browser, fill out forms with your browser, and that
calendar/diary. Photoshop caught on among graphic was about it. There was no API for reading Web sites; if
designers not only because of its powerful image editing you wanted to read the content of a site programmatical-
features, but also because of the large number of plugins ly—for example, in order to create a searchable index of
that were developed (and sold) for the platform. Microsoft all Web content—you needed to create your own “spider”
Office, much as it might be reviled by many Linux and program, as well as teach it to take apart the HTML.
open-source advocates, became popular because of its This changed in the late 1990s, when a number of
built-in programming language (VBA), as much as for its developers (most prominently, but not exclusively, includ-
built-in features. And, of course, the Firefox browser ing Dave Winer) created RSS, standing either for really
wouldn’t be half as useful to me if it weren’t for the simple syndication or RDF site summary. In either case,
half-dozen plugins that I have added to my software. the idea was to create a machine-readable, frequently
So, users push software to the limits, and software updated summary of a site’s contents. By checking a
publishers have been able to make their offerings site’s RSS feed, you could learn whether there had been
more useful by making it possible to extend their any updates. More significant, RSS feeds were formatted
programs. How does this translate into an era of in a standard way, with standard tags, making it fairly
Web-based software? And, what does this mean to easy for programs to poll a feed and extract only the
us as Web developers? information they wanted.
The answer is the increasingly ubiquitous application Unfortunately, the term RSS became both the generic
programming interface, or API. If you want your Web site term for syndication and the name for several incompati-
to be taken seriously as a platform, and not just an appli- ble (but similar) formats for syndication. A separate group
cation, you need to offer an API that lets users create, of developers created the Atom protocol, which many
modify and extend your application. APIs are becoming an people believe is superior to all of the various RSS formats.
22 | november 2007 w w w. l i n u x j o u r n a l . c o m
RSS and Atom are still popular today. The most retrieve it.
common use of these syndication feeds is for blog and This came in several different forms, all of which still
news updates, allowing users to keep track of which are used today. The first was XML-RPC, a simple RPC
sites have updated their content. But, RSS and Atom protocol that used HTTP to send an XML-encoded func-
can be used in other ways as well, providing a simple, tion invocation on a remote server. The server turned
reliable and machine-readable version of various types the XML-RPC request into a local function call and sent
of data from a Web site. If you are looking to broadcast the result of that call (or an error message) in an XML-
regularly updated data, RSS and Atom probably are encoded response. The good news was (and is) that
going to be a good starting point. XML-RPC is simple to understand and use, that there
For example, the well-known development company are implementations in many different languages, and
37signals provides an Atom feed of recent activity in its that they are generally compatible and interoperable.
Highrise contact management system. As helpful as it At the same time, XML-RPC was unable to handle
might be to look at your own feed, it would be even some of the more complex data types that people wanted
more helpful to aggregate multiple people’s feeds into a to use. Plus, it didn’t have the official seal of approval or
single viewer, allowing, for example, a manager to get complete standard that would have been necessary for it
a sense of what (and how much) employees are getting to enter the corporate arena. So, some of the original
done each day. XML-RPC developers created SOAP (originally known as
the Simple Object Access Protocol, but now an acronym
Read-Write Protocols that doesn’t expand). SOAP is more sophisticated and
The idea that a Web site could provide a regularly updated, complete than XML-RPC, but it had a great many issues
machine-parseable version of its content whetted the with compatibility, implementation and complexity. Today,
appetite of many developers for more. Many developers there are SOAP implementations for many languages, and
wanted a method to add and modify data, as well as it continues to be used in a variety of ways, despite some
24 | november 2007 w w w. l i n u x j o u r n a l . c o m
Something this sophisticated cannot use any one of And, although Amazon, Google and eBay have
the protocols that I mentioned above. Rather, Facebook demonstrated the importance and potential of a platform-
uses a combination of protocols and techniques to com- centric view, Facebook is pioneering the incorporation of
municate with your Web application, making it possible third-party applications. True, most Facebook applications
for your programs to display their output alongside other created to date are simple or trivial. But, we can expect
Facebook applications. Moreover, Facebook makes it possi- that these applications will become increasingly sophisti-
ble for your application to grab certain pieces of the user’s cated and useful over time. Facebook’s willingness to open
Facebook data, so even though your application doesn’t up to third-party developers is good for everyone—except
have access to the back-end Facebook database, it still can for competing sites, such as MySpace and LinkedIn, which
know (and display) something about the user’s friends. still appear to see themselves as standalone sites, rather
Your application even can send messages and notifications than platforms for new applications.
to the user’s friends, although Facebook has discovered This month, I explained why I find Facebook’s API to
that this can lead to spamming, so it remains to be seen be new and exciting. Next month, we’ll look at how you
exactly what happens on this front. can create your own Facebook applications. Even if you
aren’t interested in creating applications for Facebook,
Conclusion you owe it to yourself to see how the latest generation
Web sites used to be nothing more than an electronic of Web applications allow themselves to be modified,
method for publishing and reading basic information not just queried.I
encoded in HTML. But, Web sites evolved into applica-
tions, which spawned the first generation of APIs that Reuven M. Lerner, a longtime Web/database developer and consultant, is a PhD
made it possible to read and write your data. Facebook is candidate in learning sciences at Northwestern University, studying on-line
the first of the new generation of Web sites that look at learning communities. He recently returned (with his wife and three children) to
themselves as a platform more than an application. their home in Modi’in, Israel, after four years in the Chicago area.
COLUMNS
COOKING WITH LINUX
26 | november 2007 w w w. l i n u x j o u r n a l . c o m
", ),
+/ ),
8SWRFRUHVDQG
*%''55$0
8SWRFRUHVDQG
*%''55$0