LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-26-2005, 06:40 PM   #1
Temjin
LQ Newbie
 
Registered: Nov 2003
Location: Sweden
Distribution: Slackware
Posts: 10

Rep: Reputation: 0
Question Get bash to kill its children upon death


I'm running telnetd and for the login program I'm using a bash script that sets a few variables and the runs alsamixer. The point being that anyone on the local network should be able to adjust the volume by telnetting to the dedicated music box. Mostly it works fine, but there is one problem.
When a user decides to kill his telnet client (rather than the alsamixer running within) the alsamixer process on the music box doesn't die, instead it goes nuts eating up any available cpu cycles.
The way I understand it, what happens is the following:
1. When the telnet client dies, telnetd dies.
2. telnetd does not explicitly kill the login program before dying, but bash, upon having its stdin closed, exits.
3. Alsamixer freaks out.

What I want is for bash to kill its children properly before exiting. Is this possible?
Another solution is of course to write a wrapper for alsamixer, but I'd rather not.
All ideas are welcome. The less work, the better!
 
Old 05-26-2005, 07:18 PM   #2
marghorp
Senior Member
 
Registered: Jan 2004
Location: Slovenia
Distribution: Slackware 10.1, SLAX to the MAX :)
Posts: 1,040

Rep: Reputation: 45
You could put a line in bash_logout that would kill all the programs, that were run from that console (like tty1 or tty2 or any other)
 
Old 05-27-2005, 08:41 AM   #3
Temjin
LQ Newbie
 
Registered: Nov 2003
Location: Sweden
Distribution: Slackware
Posts: 10

Original Poster
Rep: Reputation: 0
Good idea!
Unfortunately, bash doesn't seem to run .bash_logout before exiting.
I'm invoking it with --login, and I've verified that .bash_profile is being run. Also, running bash manually, it does run .bash_logout upon exiting.
Perhaps bash is being killed more brutally than I first thought?

If it is of any interest, the line in inetd.conf currently looks like this:
telnet stream tcp6 nowait root /usr/sbin/tcpd in.telnetd -L /usr/local/bin/loginmixer

loginmixer is a simple script with just one line:
exec /bin/bash --login /usr/local/bin/aumixbark

aumixbark is the script that launches alsamixer (yes it's a bad name...).
It's a bit of a mess since I was unable to figure out how to give options to the login program directly from inetd.conf.

If I leave exec out of loginmixer the only difference is that I have one extra process running while the telnet session is up. When telnetd dies, so does loginmixer, but alsamixer still keeps going.

Any ideas as to what is really going on here?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Children Safe Browser oldstinkyfish Linux - Software 5 10-10-2004 04:08 PM
how do i kill a process from inside a bash script? mikaelo Programming 4 05-28-2004 08:51 AM
small bash script to kill a PID flosch Linux - General 3 05-06-2004 09:28 PM
How many children have been created... maniac01 Programming 8 03-11-2004 11:27 AM
BASH script inform user and kill process mounters Programming 3 02-11-2002 04:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration