Linux System Programming 1st Edition Robert Love instant download
Linux System Programming 1st Edition Robert Love instant download
pdf download
https://ebookfinal.com/download/linux-system-programming-1st-
edition-robert-love/
https://ebookfinal.com/download/linux-system-programming-talking-
directly-to-the-kernel-and-c-library-second-edition-robert-love/
https://ebookfinal.com/download/professional-linux-programming-1st-
edition-jon-masters/
https://ebookfinal.com/download/mastering-linux-system-
administration-1st-edition-christine-bresnahan/
https://ebookfinal.com/download/beginning-linux-programming-4th-
edition-neil-matthew/
Beginning Linux programming 3rd Edition Neil Matthew
https://ebookfinal.com/download/beginning-linux-programming-3rd-
edition-neil-matthew/
https://ebookfinal.com/download/linux-programming-by-example-the-
fundamentals-1st-edition-robbins/
https://ebookfinal.com/download/c-programming-in-linux-2nd-edition-
david-haskins/
https://ebookfinal.com/download/automating-linux-and-unix-system-
administration-2nd-edition-nathan-campi/
https://ebookfinal.com/download/unix-and-linux-system-administration-
handbook-fourth-edition-evi-nemeth/
Linux System Programming 1st Edition Robert Love
Digital Instant Download
Author(s): Robert Love
ISBN(s): 9780596009588, 0596009585
Edition: 1
File Details: PDF, 2.69 MB
Year: 2007
Language: english
www.it-ebooks.info
www.it-ebooks.info
LINUX
System Programming
www.it-ebooks.info
Other Linux resources from O’Reilly
Related titles Building Embedded Linux Programming Embedded
Systems Systems
Designing Embedded Running Linux
Hardware Understanding Linux
Linux Device Drivers Network Internals
Linux Kernel in a Nutshell Understanding the Linux
Kernel
ONLamp.com is the premier site for the open source web plat-
form: Linux, Apache, MySQL and either Perl, Python, or PHP.
www.it-ebooks.info
LINUX
System Programming
Robert Love
www.it-ebooks.info
Linux System Programming
by Robert Love
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles (safari.oreilly.com). For more information, contact our
corporate/institutional sales department: (800) 998-9938 or [email protected].
Printing History:
September 2007: First Edition.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc. The Linux series designations, Linux System Programming, images of the man in
the flying machine, and related trade dress are trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a
trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and author assume
no responsibility for errors or omissions, or for damages resulting from the use of the information
contained herein.
ISBN-10: 0-596-00958-5
ISBN-13: 978-0-596-00958-8
[M]
www.it-ebooks.info
Table of Contents
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
2. File I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Opening Files 24
Reading via read( ) 29
Writing with write( ) 33
Synchronized I/O 37
Direct I/O 40
Closing Files 41
Seeking with lseek( ) 42
Positional Reads and Writes 44
Truncating Files 45
Multiplexed I/O 47
Kernel Internals 57
Conclusion 61
www.it-ebooks.info
3. Buffered I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
User-Buffered I/O 62
Standard I/O 64
Opening Files 65
Opening a Stream via File Descriptor 66
Closing Streams 67
Reading from a Stream 67
Writing to a Stream 70
Sample Program Using Buffered I/O 72
Seeking a Stream 74
Flushing a Stream 75
Errors and End-of-File 76
Obtaining the Associated File Descriptor 77
Controlling the Buffering 77
Thread Safety 79
Critiques of Standard I/O 81
Conclusion 82
vi | Table of Contents
www.it-ebooks.info
6. Advanced Process Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Process Scheduling 162
Yielding the Processor 166
Process Priorities 169
Processor Affinity 172
Real-Time Systems 176
Resource Limits 190
9. Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
Signal Concepts 280
Basic Signal Management 286
Sending a Signal 291
Reentrancy 293
Signal Sets 295
Blocking Signals 296
www.it-ebooks.info
Advanced Signal Management 298
Sending a Signal with a Payload 305
Conclusion 306
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
www.it-ebooks.info
Foreword
There is an old line that Linux kernel developers like to throw out when they are feel-
ing grumpy: “User space is just a test load for the kernel.”
By muttering this line, the kernel developers aim to wash their hands of all responsi-
bility for any failure to run user-space code as well as possible. As far as they’re
concerned, user-space developers should just go away and fix their own code, as any
problems are definitely not the kernel’s fault.
To prove that it usually is not the kernel that is at fault, one leading Linux kernel
developer has been giving a “Why User Space Sucks” talk to packed conference
rooms for more than three years now, pointing out real examples of horrible user-
space code that everyone relies on every day. Other kernel developers have created
tools that show how badly user-space programs are abusing the hardware and drain-
ing the batteries of unsuspecting laptops.
But while user-space code might be just a “test load” for kernel developers to scoff
at, it turns out that all of these kernel developers also depend on that user-space code
every day. If it weren’t present, all the kernel would be good for would be to print
out alternating ABABAB patterns on the screen.
Right now, Linux is the most flexible and powerful operating system that has ever
been created, running everything from the tiniest cell phones and embedded devices
to more than 70 percent of the world’s top 500 supercomputers. No other operating
system has ever been able to scale so well and meet the challenges of all of these dif-
ferent hardware types and environments.
And along with the kernel, code running in user space on Linux can also operate on
all of those platforms, providing the world with real applications and utilities people
rely on.
In this book, Robert Love has taken on the unenviable task of teaching the reader
about almost every system call on a Linux system. In so doing, he has produced a
tome that will allow you to fully understand how the Linux kernel works from a
user-space perspective, and also how to harness the power of this system.
ix
www.it-ebooks.info
The information in this book will show you how to create code that will run on all of
the different Linux distributions and hardware types. It will allow you to understand
how Linux works and how to take advantage of its flexibility.
In the end, this book teaches you how to write code that doesn't suck, which is the
best thing of all.
—Greg Kroah-Hartman
x | Foreword
www.it-ebooks.info
Preface
xi
www.it-ebooks.info
with one. You’ll also want to be familiar with the basics of using gcc, gdb, make, and
so on. Plenty of other books on tools and practices for Linux programming are out
there; the bibliography at the end of this book lists several useful references.
I’ve made few assumptions about the reader’s knowledge of Unix or Linux system
programming. This book will start from the ground up, beginning with the basics,
and winding its way up to the most advanced interfaces and optimization tricks.
Readers of all levels, I hope, will find this work worthwhile and learn something
new. In the course of writing the book, I certainly did.
Nor do I make assumptions about the persuasion or motivation of the reader.
Engineers wishing to program (better) at a low level are obviously targeted, but
higher-level programmers looking for a stronger standing on the foundations on
which they rest will also find a lot to interest them. Simply curious hackers are also
welcome, for this book should satiate their hunger, too. Whatever readers want and
need, this book should cast a net wide enough—as least as far as Linux system pro-
gramming is concerned—to satisfy them.
Regardless of your motives, above all else, have fun.
xii | Preface
www.it-ebooks.info
Chapter 5, Process Management
This chapter introduces Unix’s second most important abstraction, the process,
and the family of system calls for basic process management, including the ven-
erable fork.
Chapter 6, Advanced Process Management
This chapter continues the treatment with a discussion of advanced process
management, including real-time processes.
Chapter 7, File and Directory Management
This chapter discusses creating, moving, copying, deleting, and otherwise man-
aging files and directories.
Chapter 8, Memory Management
This chapter covers memory management. It begins by introducing Unix con-
cepts of memory, such as the process address space and the page, and continues
with a discussion of the interfaces for obtaining memory from and returning
memory to the kernel. The chapter concludes with a treatment on advanced
memory-related interfaces.
Chapter 9, Signals
This chapter covers signals. It begins with a discussion of signals and their role
on a Unix system. It then covers signal interfaces, starting with the basic, and
concluding with the advanced.
Chapter 10, Time
This chapter discusses time, sleeping, and clock management. It covers the basic
interfaces up through POSIX clocks and high-resolution timers.
Appendix, GCC Extensions to the C Language
The Appendix reviews many of the optimizations provided by gcc and GNU C,
such as attributes for marking a function constant, pure, and inline.
The book concludes with a bibliography of recommended reading, listing both use-
ful supplements to this work, and books that address prerequisite topics not covered
herein.
Preface | xiii
www.it-ebooks.info
If any evolving operating system is a moving target, Linux is a rabid cheetah.
Progress is measured in days, not years, and frequent releases of the kernel and other
components constantly morph the playing field. No book can hope to capture such a
dynamic beast in a timeless fashion.
Nonetheless, the programming environment defined by system programming is set in
stone. Kernel developers go to great pains not to break system calls, the glibc devel-
opers highly value forward and backward compatibility, and the Linux toolchain
generates compatible code across versions (particularly for the C language). Conse-
quently, while Linux may be constantly on the go, Linux system programming
remains stable, and a book based on a snapshot of the system, especially at this point
in Linux’s development, has immense staying power. What I am trying to say is sim-
ple: don’t worry about system interfaces changing, and buy this book!
Most of the code in this book is in the form of brief, but usable, code snippets. They
look like this:
while (1) {
int ret;
ret = fork ( );
if (ret == -1)
perror ("fork");
}
Great pains have been taken to provide code snippets that are concise but usable. No
special header files, full of crazy macros and illegible shortcuts, are required. Instead
of building a few gigantic programs, this book is filled with many simple examples.
xiv | Preface
www.it-ebooks.info
As the examples are descriptive and fully usable, yet small and clear, I hope they will
provide a useful tutorial on the first read, and remain a good reference on subse-
quent passes.
Nearly all of the examples in this book are self-contained. This means you can easily
copy them into your text editor, and put them to actual use. Unless otherwise men-
tioned, all of the code snippets should build without any special compiler flags. (In a
few cases, you need to link with a special library.) I recommend the following com-
mand to compile a source file:
$ gcc -Wall -Wextra -O2 -g -o snippet snippet.c
This compiles the source file snippet.c into the executable binary snippet, enabling
many warning checks, significant but sane optimizations, and debugging. The code
in this book should compile using this command without errors or warnings—
although of course, you might have to build a skeleton program around the snippet
first.
When a section introduces a new function, it is in the usual Unix manpage format
with a special emphasized font, which looks like this:
#include <fcntl.h>
int posix_fadvise (int fd, off_t pos, off_t len, int advice);
The required headers, and any needed definitions, are at the top, followed by a full
prototype of the call.
Preface | xv
www.it-ebooks.info
example code does not require permission. Incorporating a significant amount of
example code from this book into your product’s documentation does require
permission.
We appreciate attribution. An attribution usually includes the title, author, pub-
lisher, and ISBN. For example: “Linux System Programming by Robert Love. Copy-
right 2007 O’Reilly Media, Inc., 978-0-596-00958-8.”
If you believe that your use of code examples falls outside of fair use or the permis-
sion given above, feel free to contact us at [email protected].
How to Contact Us
Please address comments and questions concerning this book to the publisher:
O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)
We have a web page for this book, where we list errata, examples, and any addi-
tional information. You can access this page at this address:
http://www.oreilly.com/catalog/9780596009588/
To comment or ask technical questions about this book, you can send an email to
the following address:
[email protected]
For more information about our books, conferences, Resource Centers, and the
O’Reilly Network, see our web site at this address:
http://www.oreilly.com
Acknowledgments
Many hearts and minds contributed to the completion of this manuscript. While no
list would be complete, it is my sincere pleasure to acknowledge the assistance and
friendship of individuals who provided encouragement, knowledge, and support
along the way.
Andy Oram is a phenomenal editor and human being. This effort would have been
impossible without his hard work. A rare breed, Andy couples deep technical knowl-
edge with a poetic command of the English language.
xvi | Preface
www.it-ebooks.info
Brian Jepson served brilliantly as editor for a period, and his sterling efforts continue
to reverberate throughout this work as well.
This book was blessed with phenomenal technical reviewers, true masters of their
craft, without whom this work would pale in comparison to the final product you
now read. The technical reviewers were Robert Day, Jim Lieb, Chris Rivera, Joey
Shaw, and Alain Williams. Despite their toils, any errors remain my own.
Rachel Head performed flawlessly as copyeditor. In her aftermath, red ink decorated
my written word—readers will certainly appreciate her corrections.
For numerous reasons, thanks and respect to Paul Amici, Mikey Babbitt, Keith Bar-
bag, Jacob Berkman, Dave Camp, Chris DiBona, Larry Ewing, Nat Friedman, Albert
Gator, Dustin Hall, Joyce Hawkins, Miguel de Icaza, Jimmy Krehl, Greg Kroah-
Hartman, Doris Love, Jonathan Love, Linda Love, Tim O’Reilly, Aaron Matthews,
John McCain, Randy O’Dowd, Salvatore Ribaudo and family, Chris Rivera, Joey
Shaw, Sarah Stewart, Peter Teichman, Linus Torvalds, Jon Trowbridge, Jeremy Van-
Doren and family, Luis Villa, Steve Weisberg and family, and Helen Whisnant.
Final thanks to my parents, Bob and Elaine.
—Robert Love
Boston
Preface | xvii
www.it-ebooks.info
www.it-ebooks.info
Discovering Diverse Content Through
Random Scribd Documents
The Project Gutenberg eBook of Folklore of
Wells: Being a Study of Water-Worship in East
and West
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.
Language: English
BY
R. P. MASANI, M.A.
BOMBAY:
D. B. TARAPOREVALA SONS & Co.
1918
PART I.
FOLKLORE OF BOMBAY WELLS.
CHAPTER I.
SANCTITY OF WATER.
Origin of fevers—Wrath of Shiva—Story of Ekānterio, the
malaria fiend—Closing of wells—Protests based on
religious sentiments and supernatural beliefs—Scriptural
injunctions for the use of well water—Opinions of Parsi
scholars—Some Hindu beliefs and usages—Ceremonies
requiring water drawn from seven wells—Lighting of
lamps in the niches in wells—The unwashed sect of the
Jains—Aversion to bathing—The days of the Drymais 1-8
CHAPTER II.
WATER SAINTS.
Spirits dwelling in wells—Disasters brought on by pent-up
spirits—The fortunes of the Edwardes Theatre—
Mysterious collapse of barriers—The sacred well of Alice
Building—Propitiated well-spirits avert accidents—Story
of two sisters—Oracular well of Ghoga Street—Midnight
and midday visits to wells—Ceremony of divination at
St. Oswall’s well 9-13
CHAPTER III.
PENALTY FOR DEFILEMENT.
The labourer who spat on the pavement of an oracular well
—Fate of an European girl who offended the saintly
spirit of Loveji Castle—Acts of defilement, whether
conscious or unconscious, offend the spirits—The
Nowroji Wadia house tragedy—A Damascus custom—
Destruction of the land of Logres—Concerts of the
nymphs—“The pure one” fountain of Egypt—An
Esthonian belief—A curious variant of the belief
concerning defilement—Deliberate pollution of wells so
as to constrain the rain-god—Albiruni’s interrogatories—
Doctrine of negation of knowledge 14-17
CHAPTER IV.
QUAINT PARSI BELIEFS.
Worship of cabined spirits on full moon eve—Goat-sacrifice
on marriage days—Practice of besmearing the forehead
with the blood of the victim—Non-Aryan cults imbibed
by the Aryans—Hindu and Parsi beliefs in water-spirits
compared—Antiquity of water-worship among the Parsis
—Worship of Ardevi Sura Anahita—Influence of the
genii locorum on the community—Mahomedan patron
saints of Parsi household—An anthropological puzzle—
Ecstatic possession of a Parsi woman—The Gunbow
well—Murgha Bâwâ’s well—Cures effected by the grace
of water-saints—Beliefs common to the whole world—
Association of life with motion—Water-worship in the
East has its counterpart in the history of Western
thought—Professor Robertson Smith’s description of the
worship prevailing in Arabia—Well-worship in the West
probably more widespread and primitive than in the
East 18-26
PART II.
WATER-WORSHIP IN EAST AND WEST.
CHAPTER V.
THE MOST WIDE-SPREAD PHASE OF ANIMISM.
Deification of fountains and rivers a general cult—Max
Müller’s theory of poetic personification—The spiritual
element uppermost in the worship of water—Water an
important factor during the first three days of Creation
—Rabbi Ismael’s saying—Babylonian conception of the
god Nun—Rising of Shu from water—The Akkad triad of
gods—Worship of streams absorbed by the Hittites into
their pantheon—Two triads sacred to the Phœnicians—
The Vedic god Varuna—How the conception of the night
served to convey the idea of the ocean—Greek beliefs—
Okeanos and Skamandros—Neptune, the Latin sea-god
—Nēreus, the Old Man of the Sea—The Scandinavian
god Niörd—Midsuno Kami, the water-god of Japan—The
Peruvian sea-god Virakocha—Worship of Mamacocha,
Mother Sea—The Egyptian Nile-god—Parsi festival in
honour of Ardevi Sur Anahita—The Greek goddess
Aphrodite—Wells of water bestowed by Greek saints—
Healing virtues of the waters of Egeria—Dedication of
likenesses of diseased limbs to the water-nymph Egeria
—Similar offerings to Virgin Mary at Mount Mary’s
Chapel at Bandra—The holy well of Smyrna Cathedral—
Cures effected with ordinary water just as well as with
the sanctified water—Archæological evidence of the
British cult—American examples of animistic ideas
concerning water—African rites of water-worship 29-39
CHAPTER VI.
CHRISTIAN TOLERANCE OF THE CULT OF WATER.
A non-Christian custom—Edicts of Kings, Popes and Church
Councils prohibiting the practice—Total eradication of
beliefs and customs of age-long existence impossible—
Continuance of pagan worship under Christian auspices
—A dual system of belief—Supplication of a Scottish
peasant at a sacred well—Grimm’s examination of the
result of the Christian tolerance of paganism—Mr.
Edward Clodd’s testimony 40-43
CHAPTER VII.
HOLY WELLS AND TANKS.
Worship of Khwaja Khizr—Alexander’s ramble in quest of the
blessed waters—Northern India customs—Khwaja
Saheb ka Dalya—Water of Zumzum—Mother Ganges
and Lady Jumna—Pilgrimage to the Godavari—Russian
ceremony of blessing the waters of the Neva—Sita’s
kitchen—Dr. Buchanan’s visit to the Monghyr well—The
theory of expiating sins by baths—King Trisanku’s
deadly sins and salvation—Washing of sins with the
sacred thread—Sacred wells of India—Rajput woman
turned into a male Rajput of the Solanki class—The
legendary lore of the holy wells of England—Thomas
Quiller-Couch’s notes on the holy wells of Cornwall—
Sacred wells of Scotland and Ireland 44-53
CHAPTER VIII.
HEALING WATERS.
Sanitary guardians of water—Balneotherapy and 54-65
Hydrotherapy not unknown in Talmudic times—Indian
wells and tanks renowned for medicinal properties—A
milk-bestowing well in Lonavla—The leper cured by the
Lake of Immortality at Amritsar—Virtue of the confervæ
on the surface of the Lalitpur tank—Famous hot springs
—The Devki-Unai—The springs of Vajrabai or the Lady
of the Thunderbolt—The Vali who makes the fire and
keeps it burning at the hot springs at Terka Main—The
madness-curing pool at Hamath—Mad men tumbled
headlong in the Altarnum well—The virtues of St.
Tecla’s well—Holywell, the Lourdes of Wales—The Story
of St. Winefride—Recent Holywell cures—The calamity
that befell Holywell—Other healing wells of Great
Britain—The dance round the sacred springs of Enmore
Green—St. Conan’s well—Bishop Hall’s testimony—
Sacred springs in Macedonia—Festival at Kaisariani—A
suppressed miracle—Pilgrimage described by Miss
Hamilton—Scenes in Emile Zola’s novel recalled
CHAPTER IX.
PROCREATIVE POWERS OF WATER SPIRITS.
Water-spirits conferring the blessings of parenthood—
Charms for childless women—Bathing in the water of
seven wells—The Dewali bath in the Punjab—Fertilizing
virtue ascribed to Scottish springs—General explanation
of the cult of the bath—Sterility believed to be a
disease due to demoniacal agency—Another theory—
Procreative power attributed to spirits—Testimony borne
by Professor Curtiss—Hot air vents in Syria—Belief of
the Punjabis that the fertilizing virtue of a well is
abstracted by the women bathing in it—The Jewish
belief—Conception possible in a bath—The theory in
vogue among physicians of the twelfth century—A case
recorded by Averroes—Prevalence of the theory in
Turkey—Supposed ancestors of persons bearing the
name of the Tweed—A Semong tradition 66-70
CHAPTER X.
WISHING AND CURSING WELLS.
Oracular wells inhabited by spirits gifted with powers of
divination—The Baladana Kund—Prospects of the
harvest divined by the holy well in Askot—Bread and
pins as instruments of divination—The Amorgos well—
The presiding power of the well of St. Michael—News of
absent friends given by a Cornish well—Two Wishing
wells in Walsingham Chapel—The Fairy Well in Cornwall
—Ceremonial observances taught by the priestess of
Gulval Well—Cursing wells—Varied virtues of Holy wells
—The Well of St. Keyne—Strange traditions 71-75
CHAPTER XI.
MALEFICENT WATER-GOBLINS.
Water-goblins infesting ill-omened streams and wells—
Water-spirits in India regarded as friendly dispensers of
life and fertility—Western folklore abounds in blood-
thirsty water-demons—Some mischievous water-spirits
of India—Fallen souls—A haunted vav in Vadhwan—The
Bhainsasura or buffalo-demon—The Jaté Buddi and
Jakh of Bengal—The “cups of the fairies”—A wicked
class of water-nymphs—The Greek water-nymphs—The
Sirens—The Nereids—The Black Giant and the Drakos—
Superstitions concerning drowning—Black’s explanation
in “Folk Medicine”—Prevalence of the superstition in
Scotland—No trace of it in India—Confusion of two
distinct ideas 76-83
CHAPTER XII.
RIVER WRAITHS.
The River of Death—Indian water-furies easily propitiated— 84-91
Continental water-deities demand human sacrifices—
Peg O’Nell—Peg Powler—Blood-thirsty Dee—The saying
about St. John the Baptist—Victims demanded by the
German rivers on Midsummer Day—Lord of the Wells—
In the Australian theory of disease and death none
more prominent than the water-spirit—A Macedonian
ballad of a Haunted Well—Maleficent deities responsible
for floods—Various modes of pacifying the furies—The
Nizam’s offering to the Musi—Floods caused by offence
given to patron saints of water—The sea-spirits more
powerful but less exacting that the river-wraiths—The
Narali Purnima or Cocoanut Day
CHAPTER XIII.
WHO WERE THE WATER-DEMONS?
Race-origin of the Devas or demons of old—Max Müller’s
theory—Myths of malignant spirits connected with
traditions of hostile races—Sir Laurence Gomme’s
examination of the mythic influence of a conquered
race—Bombay beliefs—Other Indian parallels—The
Moondahs and the Kathodis—The origin of the pixies—
Examination of Parsi beliefs in Mahomedan guardian-
spirits of wells—A plea for local research 92-96
CHAPTER XIV.
ANALYSIS OF THE BRITISH CULTS.
Gomme’s analysis—Table showing the effect of incoming
civilisations—Garland-dressing, pins and rag bushes—
Variants of one primitive form of rag-offering—
Arguments in favour of a megalithic date for well- 97-
worship and rag-offerings 100
PART III.
VARIED RITUALS AND OFFERINGS.
CHAPTER XV.
WATER-DIVINING AND WELL-OPENING CEREMONIES.
Jewish song of the well—Selection of suitable sites for wells
—Water-diviners—An extraordinary incident of the
Gallipoli campaign—Ceremonies connected with the 102-
digging of wells 108
CHAPTER XVI.
DECORATIONS AND OFFERINGS.
Indian methods of venerating wells—Human sacrifices—
Animal sacrifices—Ceremonies demonstrably non-Aryan
in India in original non-Aryan in Europe—A Whitsuntide
custom—Lamb, a votive thank-offering—The Ram Feast
at Holne—Substitutes for animal victims—Curious 109-
explanation for offerings of coins 113
CHAPTER XVII.
RAG WELLS AND PIN WELLS.
Rag wells and Pin wells of Great Britain—Their geographical
distribution—Henderson’s explanation of the cult—
Theory put forward by Sir John Rhys—Sir Laurence
Gomme’s examination of the theory—Other authorities 114-
—Use of wool in hanging up rags 120
CHAPTER XVIII.
A MISUNDERSTOOD INDIAN CUSTOM.
Indian custom of hoisting flags near shrines and sacred
trees—A practice quite distinct from rag-offering—How
European folklorists are misled—Confusion of flags and
rags—The flag is offered only and solely as a thank-
offering or as a mark of respect—How the rag came to
be regarded as a vehicle of disease—An explanation of 121-
two conflicting theories 127
CHAPTER XIX.
ANIMAL DEITIES OF WATER.
European belief in the presence of animals or fish as the
presiding spirits of water—These animal gods
imperfectly represented in the waters of the East—The
Nags or semi-divine beings, half men and half serpents
—Frogs and trouts and worms and flies as guardian-
spirits of wells in Europe—A pair of enchanted trout—A
medicinal spring and its presiding worm—Another
presiding genius in the semblance of a fly—Divine life of
water believed to reside in the sacred fish—Foundation
of the cult the same everywhere—Difference only in 128-
forms and rituals 131
ILLUSTRATIONS.
1. Floating of lamps during the Kartik Bath.
2. Parsis on the sea-beach in Bombay.
3. Offerings to the Gunbow Well.
4. Ganga Mâi.
5. Marjan Vidhi: Washing away of sins with the changing of the
sacred thread.
6. Ocean-worship.
7. Narali Purnima.
INTRODUCTION.
For literary conceits and dreams of authorship there is no more
powerful antidote than the tedium of official life. It radically cures all
such morbid propensities. This little book, however, owes its
inspiration to office routine. It was in connection with official
business that my interest in the subject of water-worship was
awakened about six years ago when in my capacity as Municipal
Secretary of Bombay I received several protests against requisitions
for the closing of wells.
In the course of its campaign against malaria the Municipality had
to call upon owners of wells breeding anopheles mosquitoes to close
them. The owners protested against these orders and in their
petitions they cited traditions concerning the sanctity of water and
related stories of spirits residing in the wells which to one ignorant of
the social organization and customs of the people might appear to
be nothing more than old wives’ tales and babble, or mere pretexts
to shirk civic responsibilities, but which a student of traditional lore
has learnt to prize as priceless fragments of information concerning
the condition of human thought of bygone ages. Often during one’s
investigation of such local accounts one comes across examples
where history is in close contact with popular tradition, illustrating
abundantly the inherent value of what Sir Henry Maine slightingly
called “the slippery testimony concerning savages which is gathered
from travellers’ tales.” Looked at from that point of view, the curious
beliefs and customs referred to in those petitions revealed divers
elements of sociological and ethnological importance leading back to
the days of the ancestors of the petitioners, and affording glimpses
of remote, unexplored periods of antiquity when people unknown to
history dwelt in the particular localities from which the petitioners
hailed and left behind them a heritage of their mental strivings and
conceptions concerning wells and springs and other natural objects.
All this local lore of wells established, beyond doubt, the prevalence
of water-worship amongst educated Hindus and Parsis residing in
Bombay. It was, however, a medley of many divergent elements. To
docket and classify all the constituent elements of this folklore, to
trace their origin and to throw fresh light on the different stages of
culture of the early settlers in the island of Bombay, was a task far
beyond my capacity. Nevertheless, it seemed to me it would be a sin
to allow such precious gems of information to remain buried in the
dusky archives of the Municipality. I therefore culled from the official
correspondence such gems as I could lay my hands on, made
personal investigations about local wells, gathered additional
information and read a paper on the Folklore of Bombay Wells
before the Anthropological Society of Bombay on the 30th August
1916.
It was natural that my interest in the subject should grow as I
proceeded. What struck me most during my studies and inquiries
was the striking resemblance in the traditions, customs, rites and
ceremonies prevailing in India and those in vogue in European
countries. It was clear, moreover, that until recently the cult of water
flourished in the West in a more primitive and much ruder form than
in India. I was, therefore, tempted to read before the Society a
second paper on the subject and this was followed by another on
the rituals of water-worship and the sundry offerings to water-spirits
in East and West.
It was impossible to bring within the range of these papers all the
materials I had collected. As the series was primarily intended to
expound the lore of wells only, a good deal remained unsaid
concerning the divine seas and springs and tanks and cataracts. I,
therefore, thought of completing the series and publishing a volume
embodying the varied water-cults, localising and classifying them,
and tracing, as far as possible, their genealogy with a view to
elucidating the early life of the people who lived in the different
localities from time to time and their relationship with the ancestors
of the long-forgotten races of other climes in which such ideas and
customs also prevailed. It was a very ambitious project, but I was
tempted to set about it as in the bibliography of anthropological
literature I could not find a single volume specially devoted to the
subject. I was, however, unable to make much progress for some
months owing to other engagements.
A few days ago, when I was sitting on the Versova sands, musing
on life’s uncertainties and the vanity of human wishes, recalling
Tennyson’s words “so many worlds, so much to do, so little done,
such things to be,” methought I heard a water-nymph questioning
me from under the pale-green sea-groves: “How many years wilt
thou dream away before thou completest that work? Why not
immediately convey to thy readers our invitation to the concerts of
the nymphs?” At once I recalled that eight years had rolled by since
I had resolved to complete another series of anthropological papers,
viz., Naming Customs and Name Superstitions, just as I had thought
of elaborating the water-worship series, but that I had not been able
to take the work in hand in the midst of rapidly increasing daily
duties. What chance was there of better success in regard to this
new work? I, therefore, thought it advisable to publish the papers as
read before the Society without further delay. Their publication in
book-form has, however, necessitated a somewhat unsatisfactory
arrangement of chapters, and for this and other demerits I owe an
apology to the reader.
It might perhaps be said that such a gallimaufry of divers tales
and traditions, beliefs and superstitions long current among different
people in different countries treats the reader to nothing new. It
might also be urged that these traditions and customs are mere
survivals of a particular phase of animism with which we are all
familiar, that we all know that from remote ages our ancestors have
peopled trees and plants, stocks and stones, dales and hills, and
seas and springs with all sorts of spirits, visible and invisible, and
that it is upon this spirit-world of prehistoric man that the primeval
nature-worship of our Aryan ancestors was based, upon which again
rest the religions and philosophies of the civilised world. This is all
very true. Veneration of water is undoubtedly a phase of nature-
worship. The student of history knows why from the remotest ages
Egypt, Babylon, India and China became centres of population in the
East and why the plains of Lombardy and Netherlands attracted
waves of humanity in the West. Naturally, man gravitated towards
districts where food was easily obtainable. Valleys and plains
fertilized by springs became his home. Water to him was not only
the prime necessity of life, but the birth-place, so to say, of life.
Moreover, the primitive mind associated life with motion. It saw
spirits in rolling stones and swinging boughs. How could it remain
unconscious of the spirits controlling the many-sounding seas and
bubbling rivers and tumbling waterfalls? This is the raison d’être of
the universality of water-worship. No new work on the folklore of
wells is needed to tell us that, but, as I have just stated, such
folklore contains valuable details of social conditions and the early
history of races and if it puts in the hands of the student of
antiquities a key to the sealed book of some unexplored stages of
the cultural history, howsoever fragmentary, of forgotten races, its
publication would not be wholly in vain.
Races flourish and vanish, but their concepts and customs live in
their successors. These successors are not necessarily their
descendants. Often they are invaders and conquerors, sometimes
refugees, professing altogether different creeds, but with the estates
and objects which they inherit from their predecessors they also
inherit their mental strivings and traditions and customs and hand
these down from generation to generation. These in their turn
influence others, wherever they go. Thus it is that we see ancient
customs and ceremonies observed, even to this day, with very little
variation, by different communities, even though separated by
oceans.
Numerous illustrations may be given of this parallelism of beliefs
prevailing in different places and their persistence in different culture
eras. One remarkable instance is the preservation of the bridge-
sacrifice traditions. It is referred to by Sir Laurence Gomme in
Folklore as an Historical Science in the course of his analysis of the
legend of the Pedlar of Lambeth and the treasure stories centering
round London Bridge. The bridge was the work of the Romans of
Lundinium—a marvellous enterprise in the eyes of the Celtic
tribesmen who believed that the building of the bridge was
accompanied by human sacrifice. This is confirmed by the
preservation in Wales of another tradition relating to the “Devil’s
Bridge” near Beddgelert. “Many of the ignorant people of the
neighbourhood believe that this structure was formed by
supernatural agency. The devil proposed to the neighbouring
inhabitants that he would build them a bridge across the pass on
condition that he should have the first who went over it for his
trouble. The bargain was made, and the bridge appeared in its
place, but the people cheated the devil by dragging a dog to the
spot and whipping him over the bridge.” When the Calcutta
authorities proposed to build a bridge over the Hoogly River, the
ignorant masses apprehended that the first requirement would be a
human sacrifice for the foundation. The news went to England from
the London and China Telegraph from which the Newcastle Chronicle
of 9th February 1889 copied the following statement:—
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookfinal.com