LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 03-11-2009, 02:58 PM   #1
alirezan1
Member
 
Registered: Nov 2004
Location: Vancouver
Distribution: Ubunty, CentOS ,Mandriva, Gentoo, RedHat, Fedora, Knoppix
Posts: 147

Rep: Reputation: 15
Strange behavior when killing bash through a script


Hi,
Here's the problem:

I want to unmount a volume but I get the error message that is is currently busy. I look at the users that are logged in, and I see someone is holding it open through shell... I want to force unmount and release the device so that I can continue shutting down the disk, but I can't. My idea was to kill ALL the bash sessions except the one that I have open before unmounting. This way, if someone has the volume open, killing the session releases it. right? So, here's what I did:

Quote:
myPID=$$
PIDs=`ps aux | grep bash | grep -v $myPID | awk '{print $2}'`
for PID in $PIDs; do
if [ $PID -ne $myPID ]; then
kill -SIGKILL $PID
fi
done
I know there's a redundant check for myPID...

So, the code seems to work and it kills the sessions alright, but it kills my parent session and therefore it logs me out...and the strangest part is that, when I try to login, I can't! I can't even enter the username in full...it keeps saying login incorrect and that's it...
In my first try, take a look at ^M when I hit enter...what's that about? I know it's DOS CR character but what's it doing here?


Quote:
mypc login: root^MPassword:
Login incorrect

login: r
Login incorrect

login: r
Login incorrect

mypc login: ^M
mypc login: ^M
mypc login: ^M
mypc login: ^M
mypc login: ^M
mypc login: ^M
mypc login: ^M
Thanks

Last edited by alirezan1; 03-11-2009 at 03:03 PM.
 
Old 03-11-2009, 04:07 PM   #2
x_terminat_or_3
Member
 
Registered: Mar 2007
Location: Plymouth, UK
Distribution: Fedora Core, RHEL, Arch
Posts: 342

Rep: Reputation: 38
Better you use lsof to determine what process is keeping the file system busy.

Example:

Code:
lsof | grep /home
As for the caret M thing. I have seen that once or twice, not sure what that is about though.
 
Old 03-12-2009, 06:36 PM   #3
alirezan1
Member
 
Registered: Nov 2004
Location: Vancouver
Distribution: Ubunty, CentOS ,Mandriva, Gentoo, RedHat, Fedora, Knoppix
Posts: 147

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by x_terminat_or_3 View Post
Better you use lsof to determine what process is keeping the file system busy.

Example:

Code:
lsof | grep /home
As for the caret M thing. I have seen that once or twice, not sure what that is about though.
Thanks. I started using lsof now but still I have the same problem. When I have a device open and I run the script to kill the session, everything goes crazy and I have to reboot to get things back to normal.

Maybe this helps: I log in through /dev/console

Thanks
 
Old 03-12-2009, 07:29 PM   #4
alirezan1
Member
 
Registered: Nov 2004
Location: Vancouver
Distribution: Ubunty, CentOS ,Mandriva, Gentoo, RedHat, Fedora, Knoppix
Posts: 147

Original Poster
Rep: Reputation: 15
okay, I just realized, everything goes crazy when I call my script that kills bash from my C code. When I call it from bash directly, everything's fine...

Anybody knows why this happens?

Thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
awk strange behavior in bash bingmou Linux - Software 7 09-18-2008 11:27 AM
killing child processes of a bash script results in strange random kills omnio Programming 6 03-12-2007 07:35 AM
BASH script showing random behavior chatterbug89 Programming 12 07-19-2005 10:45 PM
strange sed/bash behavior mpdavig Programming 1 07-24-2004 02:27 AM
Strange Script Behavior Stranger Linux - General 0 02-18-2004 03:30 AM


All times are GMT -5. The time now is 06:46 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration