Would this work/do what you want?
Code:
$ kill -s 8 pid_of_shell_session
Unfortunately, this requires you to make a system call in whichever language you are writing this in; while I have never seen the problems with system calls, some people consider it "poor programming practice" - which I can understand for portability issues, but normally, I would think that if you are asking a question like this, it is not intended for portability.
