2

I have created the following script:

#!/bin/bash
while :
do
    echo "1" >> test.txt
    sleep 1
done

If I run the command using ./exm.sh & it runs on the background as expected and it appends 1 to the file test.tx

After a few minutes I type logout, as far as I know the expected behaviour is to close all the children processes of the session, but if I login again and run ps auwx | grep exm, the process is still there and it is writing to the file. Is this the expected behaviour? I have the same results with fresh installation of CentOS 7 and Ubuntu latest.

3
  • 5
    possible duplicate: serverfault.com/questions/115999/…
    – nKn
    Sep 16, 2015 at 20:31
  • @nkn Possible but I try to give shopt -s huponexit and run the script. It remains alive. Interesting, as always, to read Gilles on Unix SE page about how to kill process group...
    – Hastur
    Oct 1, 2015 at 15:37
  • Gotcha: trap "pkill -P $$" EXIT and after execute the script and whatever... when you exit it will kill all the children of the terminal. But the reason why shopt -s huponexit doesn't work remain.
    – Hastur
    Oct 1, 2015 at 15:48

1 Answer 1

0

It is not what is commonly configured on different OS. If you want to change the behavior of your logout, you can edit file 1. ~/.bash_logout -if you are using bash 2. ~/.logout -if you are using csh

Please see reference for more info. Unix Logout Command

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .