homeGeek CultureWebstoreeCards!Forums!Joy of Tech!AY2K!webcam

The Geek Culture Forums


Post New Topic  New Poll  Post A Reply
my profile | directory login | | search | faq | forum home
  next oldest topic   next newest topic
» The Geek Culture Forums   » Techno-Talking   » Math-a-holics and Code Junkies   » exit init without kernel panic

 - UBBFriend: Email this page to someone!    
Author Topic: exit init without kernel panic
nerdwithnofriends
Uber Geek
Member # 3773

Icon 1 posted April 11, 2005 21:20      Profile for nerdwithnofriends     Send New Private Message       Edit/Delete Post   Reply With Quote 
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!

--------------------
"The Buddha, the Godhead, resides quite as comfortably in the circuits of a digital computer or the gears of a cycle transmission as he does at the top of a mountain or in the petals of a flower." - Robert M. Pirsig

Posts: 948 | Registered: Mar 2005  |  IP: Logged
quantumfluff
BlabberMouth, a Blabber Odyssey
Member # 450

Member Rated:
5
Icon 1 posted April 12, 2005 06:31      Profile for quantumfluff     Send New Private Message       Edit/Delete Post   Reply With Quote 
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.
Posts: 2902 | From: 5 to 15 meters above sea level | Registered: Jun 2000  |  IP: Logged
Brother Dysk
Geek Larva
Member # 3777

Rate Member
Icon 1 posted April 12, 2005 08:32      Profile for Brother Dysk     Send New Private Message       Edit/Delete Post   Reply With Quote 
That sounds dubious, given that Linux did not exist in 1980. I assume this was some other UNIX, then?
Posts: 25 | From: Hong Kong | Registered: Apr 2005  |  IP: Logged
quantumfluff
BlabberMouth, a Blabber Odyssey
Member # 450

Member Rated:
5
Icon 1 posted April 12, 2005 10:32      Profile for quantumfluff     Send New Private Message       Edit/Delete Post   Reply With Quote 
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"
Posts: 2902 | From: 5 to 15 meters above sea level | Registered: Jun 2000  |  IP: Logged
n4dmx
Geek
Member # 3177

Member Rated:
5
Icon 1 posted April 12, 2005 14:56      Profile for n4dmx     Send New Private Message       Edit/Delete Post   Reply With Quote 
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]

Posts: 218 | From: Georgia | Registered: Dec 2004  |  IP: Logged
drunkennewfiemidget
BlabberMouth, a Blabber Odyssey
Member # 2814

Member Rated:
4
Icon 1 posted April 12, 2005 16:15      Profile for drunkennewfiemidget     Send New Private Message       Edit/Delete Post   Reply With Quote 
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?

Posts: 4897 | From: Cambridge, ON, Canada | Registered: Jun 2004  |  IP: Logged
nerdwithnofriends
Uber Geek
Member # 3773

Icon 1 posted April 12, 2005 19:33      Profile for nerdwithnofriends     Send New Private Message       Edit/Delete Post   Reply With Quote 
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.

--------------------
"The Buddha, the Godhead, resides quite as comfortably in the circuits of a digital computer or the gears of a cycle transmission as he does at the top of a mountain or in the petals of a flower." - Robert M. Pirsig

Posts: 948 | Registered: Mar 2005  |  IP: Logged
nerdwithnofriends
Uber Geek
Member # 3773

Icon 1 posted April 12, 2005 19:35      Profile for nerdwithnofriends     Send New Private Message       Edit/Delete Post   Reply With Quote 
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.

--------------------
"The Buddha, the Godhead, resides quite as comfortably in the circuits of a digital computer or the gears of a cycle transmission as he does at the top of a mountain or in the petals of a flower." - Robert M. Pirsig

Posts: 948 | Registered: Mar 2005  |  IP: Logged


All times are Eastern Time  
Post New Topic  New Poll  Post A Reply Close Topic    Move Topic    Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:

Contact Us | Geek Culture Home Page

2015 Geek Culture

Powered by Infopop Corporation
UBB.classicTM 6.4.0



homeGeek CultureWebstoreeCards!Forums!Joy of Tech!AY2K!webcam