Deprecated: mb_strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /usr/local/www/apache24/data/libraries/vendor/joomla/string/src/phputf8/mbstring/core.php on line 41
Deprecated: mb_strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /usr/local/www/apache24/data/libraries/vendor/joomla/string/src/phputf8/mbstring/core.php on line 41
Blog
- Details
- Written by: Philippe MB
- Category: Blog
- Hits: 33
I recently had the need to reboot the machine in a C++ program (more on that later). Here's what I came up with.
void rebootMachine() {
#ifdef __linux__
// For Linux
system("/sbin/shutdown -r now > /dev/null 2>&1");
system("/etc/shutdown -r now > /dev/null 2>&1");
system("/bin/shutdown -r now > /dev/null 2>&1");
#else
std::cerr << "Unsupported operating system." << std::endl;
#endif
std::cerr << "Reboot: must be superuser." << std::endl;
}
I was wondering what the /etc/shutdown entry is, it turns out that's for Slackware Linux. The bit at the end with the ampersand and stuff, is for redirecting stderr to stdout, and stdout is sent to /dev/null. That way there's no noise in the terminal.
That's about it for this entry. Have fun, as always.