In Chinese folk beliefs, King Yama is the judge of the dead, who presides over the hell and is responsible for the life, death and transmigration of human beings. He's said to have a book listing the length of life of every individual. When someone's life in the mortal world has come to an end, King Yama would order fearsome guardians of hell to bring the newly dead to the hell for judgment. If the person did good things before death, they could be brought to heaven and enjoy good wealth; if they did evil things, they could be sent to the hell for punishment.
There was no concept of King Yama in ancient China till Buddhism was introduced to China via ancient India, when the belief in King Yama as the god of hell became entrenched. The term Yama originally means "trussing up" in Sanskrit, referring to trussing up sinners.
Later, due to the interactions between Buddhism and Taoism, the indigenous Chinese religion, variations of King Yama with Chinese flavors were developed--the Ten Kings of Hell. They have their own functions and powers as well as ways to punish sinned ghosts.
In folk culture, there are lots of popular sayings ab0ut King Yama, such as "when King Yama is away, the ghosts are free to do whatever they want", which means when someone in charge is absent, his underlings run wild; the saying "it's easy to meet King Yama, but the devils are hard to tackle" means low-ranking officials are even more difficult to deal with than their superiors; and the saying "if King Yama rules that your life ends at the third watch (midnight), you can't live to the fifth (dawn)" reflects "the fatalistic belief ab0ut the length of life".