How do I kill a remote login session as well as processes started inside it?

Solution Unverified - Updated -

Issue

  • How do I kill a remote login session as well as processes started inside it?
  • If the user terminates the SSH session by hitting the X button, it leaves the script processes running.
  • How can I configure the .profile to clean up (kill) the processes if the user terminates the SSH session?
  • We have added below script inside .profile which is not working:
set -x
PATH=$PATH:$HOME/bin
export PATH
trap "kill -15 0; exit" EXIT INT HUP
scriptname
kill -15 0

Environment

  • Red Hat Enterprise Linux 6.X
  • util-linux
  • ssh

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.