Using the function kill() you can end the process ,for this you need the process id .The function raise() will end the current process .

Code:
man 2 kill
man raise
In the kill function you can send a signal as a second argument to end the process.There are various signals to do this like (SIGKILL,SIGSROT,SIGTERM,etc).