This website explains and has examples of doing this.
Hope it helps you…
As you probably learned, the above link didn’t help at all. The direct answer to your question is simply to use the ENDJOB command.
Ending those jobs isn’t the problem. The problem is in figuring a way to tell that they’re inactive. Technically, the only way to do it is to connect to the remote system and materialize the remote job to analyze its activity. The session might be executing a long-running process that <i>makes it appear</i> to be inactive on your system.
Short of doing that kind of analysis, there is no way unless you choose some guidelines. Then you write a program to check the jobs and end them when the guidelines are broken.