what does shutdown -p command do? - linux

In Linux, what does shutdown -p command do, will it directly power off the system without Halting? if it halts the system first then power off, then can we directly power off without halting using any command?

shutdown -P sends an ACPI signal telling the computer to completely power off. However, the shutdown command by default powers off the machine, so unless you for some reason need to specify to power off, the normal shutdown command will do it.
You don't need to use any halt commands before using shutdown to power off, either, shutdown -P will completely power off the system without any need to run any halting commands.

Related

unable to run tview application configured in /etc/inittab

I am attempting to run an application using tview to show some telemetry. The application runs fine when invoked from the cmdline as normal. When I update my inittab to run the application:
c1:2345:respawn:/usr/sbin/systatus 38400 tty1 linux
That is when I see cannot open /dev/tty, No such device or address, a reference a line number where I am calling tview.Application.Run. The file / device does exist.
Any ideas as to how I might get around this?
I am referencing this:
GoLang - termbox: panic: open /dev/tty: no such device or address
even though I'm NOT using using termbox, the problem is the same. Is it a fair assumption that anything I launch under /etc/inittab is non-interactive? Is there anyway to disable the interactive part in termbox? I don't see any public functions to do such a thing.
This works, but may be a bad idea.
c1:2345:respawn:/usr/sbin/systatus </dev/tty1
In any case, I need to disable the default ctrl+c handler so that this remains running.

How exactly a 'shutdown -h' "HALT" differ from "shutdown" in linux

Suppose I have 20 process/deqamons running in my linux system,
How different the HALT will have an effect on my process/deamons, when compared to a SHUTDOWN
Generally, one uses the shutdown command. It allows a time delay and warning message before shutdown or reboot, which is important for system administration of multiuser shell servers; it can provide the users with advance notice of the downtime.
As such, the shutdown command has to be used like this to halt/switch off the computer immediately (on Linux and FreeBSD at least):
shutdown -h now
Or to reboot it with a custom, 30 minute advance warning:
shutdown -r +30 "Planned software upgrades"
After the delay, shutdown tells init to change to runlevel 0 (halt) or 6 (reboot). (Note that omitting -h or -r will cause the system to go into single-user mode (runlevel 1), which kills most system processes but does not actually halt the system; it still allows the administrator to remain logged in as root.)
Once system processes have been killed and filesystems have been unmounted, the system halts/powers off or reboots automatically. This is done using the halt or reboot command, which syncs changes to disks and then performs the actual halt/power off or reboot.
On Linux, if halt or reboot is run when the system has not already started the shutdown process, it will invoke the shutdown command automatically rather than directly performing its intended action. However, on systems such as FreeBSD, these commands first log the action in wtmp and then will immediately perform the halt/reboot themselves, without first killing processes or unmounting filesystems.
On POSIX systems the shutdown command switches runlevels, and executes the appropriate scripts.
On FreeBSD the "halt" command is an ACPI thing...
If you have particular concerns or would like to know things the general documentation wouldn't readily address, please feel free to refine your query.

Killing a process windows CE

I need to implement a program that will run on Windows CE 6.0, in C++, and that aims to kill a specific process at a specific moment.
I have tried to use 'TerminateProcess(ProcessHandle, ExitCode)'. It works, and kills the process whose handle I passed. However, when killing the specific process I want to kill, the machine stops responding, which is not acceptable.
I can kill the process via tellnet, if I use:
telnet 10.120.12.5 (IP of the Windows CE machine)
shell -d
kp 6522589 (example ID of the proccess)
That works. It kills the process and the machine does not stop running.
So the question is, how can I insert this command into my code? or, how can I call a script which does this from my code? (the script will have to be stored inside the windows CE machine).
Any other suggestion will be welcome.
How do you get the ProcessHandle? You usually need to free it with CloseHandle() after you are done with it (after calling TerminateProcess()).
You can use CreateProcess() to run another program, e.g. the shell/kp program.

Start process via SSH and GDB?

This question sounds very stupid to me, but if this is somehow possible it would be really helpful.
My application is crashing and I need to debug it. And I run this application in another computer, via SSH (it's an HTTP server). If I could leave a terminal running the application over GDB and SSH all the time, I'd be able to find the bugs. But I don't have a free computer to do that. What can I do? Is there a way to start GDB with nohup(1) plus &> and stuff like that, so I can see GDB output (where command, for example) later?
A classical Unix program called screen is your friend (or its competitor tmux). It allows to keep a virtual console open across multiple logins:
screen
starts such a session; using you can detach from that; using
screen -r
you can reconnect to it later.
However, you don't even need that; just make your program leave a core dump when it crashes; ulimit -c unlimited says "every program that crashes leaves a core dump"; you can then just open the core dump using gdb later on, and everything will be as if you ran the program inside gdb when it crashed.
gdb core.123456

What can cause SIGHUP to be generated?

We have about 40 computers running identical hardware and software. They all run Ubuntu 11.10. They all have just one user account to log in. The .profile file is set up to launch a daemon process. The code for the daemon is written in C.
Once in a few weeks, we get a report that the daemon is no longer running. This does not happen on all computers but just one or two. We cannot reproduce the problem consistently.
Looking at the code, the application quits when it receives either SIGHUP or SIGTERM.
As I understand, SIGHUP is generated when a user logs off. In our case, the user never logs off. I am wondering if it is possible that SIGHUP could have been generated for some other reason. Any other thought would be appreciated.
Well, there are a couple of things to note about SIGHUP. Firstly, its origin is from the concept of a hang-up, i.e. loss of connection to a console over something like a modem. In modern parlance this generally means it has lost its controlling tty. Unless you've taken care to detach from your tty, any program started in a given terminal will receive a SIGHUP when the terminal is closed. See here for details on how to do this in your program. Other options include:
running your program inside screen or tmux
run your program with nohup or some other daemonising framework
The other possibility is something is deliberately sending your process a SIGHUP which by "tradition" is often used to signal a process that it should re-read its configuration.
Signals can be sent using kill utility or kill syscall.
Of course, you can try and find out who is sending that signal or disconnecting your terminals or network connections, but there is simpler practical way to fix your problem.
When code is supposed to run as a daemon, but really isn't (just like yours), there is a wrapper that can turn any program into daemon. Surprise - this wrapper is called daemon! It has lots of options, probably most importantly for you, option to automatically restart your utility should it ever die for any reason.
If this command is not installed on your Ubuntu, just sudo apt-get install daemon, and man daemon to get started.

Resources