This is topic exit init without kernel panic in forum Math-a-holics and Code Junkies at The Geek Culture Forums.


To visit this topic, use this URL:
http://www.geekculture.com/cgi-bin/ultimatebb/ultimatebb.cgi?ubb=get_topic;f=17;t=000159

Posted by nerdwithnofriends (Member # 3773) on April 11, 2005, 21:20:
 
Hello, all, it's me again. Pretty simple question this time: how does the init process on a linux system tell the kernel that the machine is ready to shut down? init isn't allowed to simply exit, else the kernel raises a panic.
Thanks abunch!
 
Posted by quantumfluff (Member # 450) on April 12, 2005, 06:31:
 
I believe it exits. init waits for all it's children to die, leaving itself as the only process running. When it exits, the kernel has 0 processes left, and halts. Of course, last time I read kernel sources seriously was in 1980, so I could be wrong by now.
 
Posted by Brother Dysk (Member # 3777) on April 12, 2005, 08:32:
 
That sounds dubious, given that Linux did not exist in 1980. I assume this was some other UNIX, then?
 
Posted by quantumfluff (Member # 450) on April 12, 2005, 10:32:
 
Linux borrows a huge amount from various traditional unixes. I don't remember if it was BSD 2.11 or ATT V7 which I was using at the time. Still, if you must be certain, "Use the source Luke"
 
Posted by n4dmx (Member # 3177) on April 12, 2005, 14:56:
 
Init controls the runlevel scripts, among other things.

When you shutdown, init tells the system to run the script "rc.0" or something similar (depending on the distro) which will send the system into runlevel 0, stopping all processes.

Type "telinit 0" at the command line, or "init 0" if that didn't work to see what happens (be root for this). [Smile]
 
Posted by drunkennewfiemidget (Member # 2814) on April 12, 2005, 16:15:
 
When you shut down the system, init is called with a runlevel of (usually) 0. (telinit 0 to try that out, as someone else already said). When init enters a runlevel of 0, it shuts down all programs and services, then it sends a TERM signal to all programs still remaining, gives them a few seconds to die cleanly, and then sends a KILL to them so they go away no matter what. the linux kernel code simply does an execve of init() and if it ever returns, it panics, so I'd imagine shutdown would kill everything so that only itself and init continues to run, and then sits in an endless loop..

If you want to test that, compile your kernel with sysrq, and then do a shutdown -h now (preferably without apm enabled so it doesn't automatically shut your box off for you), and then type ALT-SYSRQ-P and it will show you what the current process running is.. is it always shutdown?
 
Posted by nerdwithnofriends (Member # 3773) on April 12, 2005, 19:33:
 
alright everybody, i'm not retarded when it comes to shutting down a linux system. I was just wondering what exactly went into it...
anyways, i think i'll try what drunknewf said. I tried writing a really simple C program that used the exit() system call instead of just returning zero.
it didn't work.
I'm thinking the infinite loop thing is the way to go, i'll have to give it a try and get back to y'all.
 
Posted by nerdwithnofriends (Member # 3773) on April 12, 2005, 19:35:
 
okay, i guess i'll share what i've learned.
init controls EVERYTHING. shutdown /reboot/ telinit are just control programs that write to /dev/initctl, which is a FIFO. init reads this and does various actions depending on what the control program writes to teh FIFO.
looking at the SysVInit sources, i think it just enters an infinite loop when it shuts down and the kernel sees this and turns off the machine.
 


© 2015 Geek Culture

Powered by Infopop Corporation
UBB.classicTM 6.4.0