coderodde
coderodde

Reputation: 977

Nice interaction of shutdown utility with terminal under Mac OS X

all!

A question to all the users of Mac OS X who have used shutdown utility to appoint a shutdown sequence in the nearby future:

If you ever looked at its output, you may have noticed that shutdown prints some information as the time point specified approaches, but (!) if you press enter, you are back in bash. (It seems like shutdown is able to print to its terminal while running in background.)

How does it do it? I would appreciate relevant C code snippets or links.

Thanks in advance!

Upvotes: 0

Views: 386

Answers (1)

ObscureRobot
ObscureRobot

Reputation: 7336

Shutdown just sends a message to the init system. init is printing the message in the shell. This is because Unix was previously used to run multi-user systems, and init needed to tell everyone that the system is going down, not just the sysadmin running shutdown.

It sounds like you want to write some code that appears to exit immediately, but still spews stuff out to the console. This is rather obnoxious behavior, from a user's perspective, so please don't do this.

However, you can easily do it with a shell script:

#!/bin/sh
sleep 60
echo "feeling sleepy?"

Then run it in the background

$ ./sleepy.sh &

Upvotes: 1

Related Questions