LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Strange behavior when killing bash through a script (http://www.linuxquestions.org/questions/linux-newbie-8/strange-behavior-when-killing-bash-through-a-script-710843/)

alirezan1 03-11-2009 03:58 PM

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

x_terminat_or_3 03-11-2009 05:07 PM

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.

alirezan1 03-12-2009 07:36 PM

Quote:

Originally Posted by x_terminat_or_3 (Post 3472368)
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

alirezan1 03-12-2009 08:29 PM

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


All times are GMT -5. The time now is 10:18 AM.