Silkworms are really caterpillars, the larval form of a moth.
The silkworm is one of the few insects that are truly domesticated and cannot survive without humans. Silkworms are kept to produce silk. They consume copious amounts of mulberry tree leaves. When eventually the silkworm pupates and it spins a cocoon for protection made out of a single silk thread. Humans then boil the cocoon, which kills the silkworm, and process the silk. In many countries, including China, the pupae are then eaten.
If the silkworm pupa is not killed for its silk it will develop into a moth — the adult form of the silkworm.
Even though the pupae of other caterpillars have been processed for silk, silkworms are the most well known sources of it. While silkworm silk is the easiest to process, spider silk is a lot stronger. Researches have experimented with the most bizarre ideas to get other animals to produce spider silk when someone finally realized the obvious: in order to produce easy to process silk you need silkworms. Thus spider genes have been crafted into genetically engineered silkworms that can produce easy to harvest silk with spider silk improvements.
Researchers hack silkworm genome to get spidery silk.
Silk on Wikipedia.