Sericulture, or silk farming, is the rearing of silkworms for the production of raw silk. Silkworm larvae are fed mulberry leaves, and, after the fourth molt, climb a twig placed near them and spin their silken cocoons. The silk is a continuous-filament fiber consisting of fibroin protein. Single filaments are combined to form thread. This thread is drawn under tension through several guides and wound onto reels. The threads may be plied together to form yarn. After drying the raw silk is packed according to quality.
The silk moth lays eggs. When the eggs hatch, the caterpillars are fed mulberry leaves. When the silkworms are about 25 days old, they are 10,000 times heavier than when they hatched. They are now ready to spin a silk cocoon. The silk is produced in two glands in the silkworm's head and then forced out in the liquid form. The silk solidifies when it comes in contact with the air. The silkworm spins approximately 1 mile of filament and completely encloses itself in a cocoon in about two or three days, but due to quality restrictions, the amount of usable silk in each cocoon is small. The silk is obtained from the undamaged cocoons by brushing the cocoon to find the outside end of the filament.
For more details: http://dsource.in/resource/cocoon-formation