Hot answers tagged

166

chaos' answer is what some documentation says. But it's not what systemd actually does. (It's not what van Smoorenburg rc did, either. The van Smoorenburg rc most definitely did not ignore LSB headers, which insserv used to calculate static orderings, for starters.) The Freedesktop documentation, such as that "Incompatibilities" page, is in fact wrong, ...


161

The init process is always assigned PID 1. The /proc filesystem provides a way to obtain the path to an executable given a PID. In other words: nathan@nathan-desktop:~$ sudo stat /proc/1/exe File: '/proc/1/exe' -> '/sbin/upstart' As you can see, the init process on my Ubuntu 14.10 box is Upstart. Ubuntu 15.04 uses systemd, so running that command ...


90

2016 Update Most answers here are five years old so it's time for some updates. Ubuntu used to use upstart by default but they abandoned it last year in favor of systemd - see: Grab your pitchforks: Ubuntu to switch to systemd on Monday (The Register) Because of that there is a nice article Systemd for Upstart Users on Ubuntu wiki - very detailed ...


83

There is no difference in them. Internally they do exactly the same thing: reboot uses the shutdown command (with the -r switch). The shutdown command used to kill all the running processes, unmount all the file systems and finally tells the kernel to issue the ACPI power command. The source can be found here. In older distros the reboot command was forcing ...


80

The disable didn't work because the Debian /etc/X11/default-display-manager logic is winding up overriding it. In order to make text boot the default under systemd (regardless of which distro, really): systemctl set-default multi-user.target To change back to booting to the GUI, systemctl set-default graphical.target I confirmed those work on my Jessie ...


68

When a process exits, all its children also die (unless you use NOHUP in which case they get back to init). This is wrong. Dead wrong. The person saying that was either mistaken, or confused a particular situation with the the general case. There are two ways in which the death of a process can indirectly cause the death of its children. They are related ...


61

Three answers written in 2014, all saying that in Unices and in Linux the process is reparented to process #1 without exception. Three wrong answers. ☺ As the SUS says, quoted in one of the other answers here so I won't quote it again, the parent process of orphaned children is set to an implementation-defined process. Cristian Ciupitu is right to ...


59

You can poke around the system to find indicators. One way is to check for the existence of three directories: /usr/lib/systemd tells you you're on a systemd based system. /usr/share/upstart is a pretty good indicator that you're on an Upstart-based system. /etc/init.d tells you the box has SysV init in its history The thing is, these are heuristics that ...


58

I've stepped into this problem myself and decided to do some tests. I fully agree with the answer that one should package for each distro separately, but sometimes there are practical issues that prevent that (not least manpower). So for those that want to "auto-detect" here's what I've found out on a limited set of distros (more below): You can tell ...


53

System 5 init will tell you only a small part of the story. There's a sort of myopia that affects the Linux world. People think that they use a thing called "System 5 init", and that is both what is traditional and the best place to start. Neither is in fact the case. Tradition isn't in fact what such people say it to be, for starters. System 5 init and ...


33

From man 2 kill: The only signals that can be sent to process ID 1, the init process, are those for which init has explicitly installed signal handlers. This is done to assure the system is not brought down accidentally. That is, it is possible for init to do whatever it likes upon receiving SIGKILL (including exiting), but systemd's init does not ...


30

For the second question, the answer is no and you should have a look at Resources for portable shell programming. As for the first part - first of all, you certainly have to be careful. I'd say perform several tests to make sure - because the fact that someone does have systemd (for ex.) installed, does not mean it is actually used as the default init. Also,...


29

Processes need to have a parent (PPID). The kernel, despite not being a real process, is nevertheless handcrafting some real processes like at least init, and is giving itself the process ID 0. Depending on the OS it might or might not be displayed as a process in ps output but is always displayed as a PPID: eg on Linux: $ ps -ef|head UID PID PPID ...


28

This is actually quite a difficult problem. One of the major difficulties is that the places where one most often wants to do this are the places where it's quite likely that one will be in the middle of installing or changing stuff. Another is that there's a subtle but very important difference between the system management toolset that is installed, the ...


24

On RPM-based systems, you can query the RPM database to see what package provides /sbin/init. For example: fedora:~$ rpm -qf /sbin/init systemd-216-24.fc21.x86_64 centos:~$ rpm -qf /sbin/init upstart-0.6.5-12.el6_4.1.x86_64 opensuse:~$ rpm -qf /sbin/init systemd-sysvinit-44-10.1.1.i586 If you just want the package name, and not version, you could add the ...


21

On newer Upstart systems, a session init process is started when you login using the GUI. Since Ubuntu uses Upstart, there's an init process for your session. Test it out using pstree -ps $$ in a terminal: $ pstree -ps $$ init(1)───lightdm(1741)───lightdm(9511)───init(9526)───/usr/bin/termin(9570)─┬─gnome-pty-helpe(9734) ...


18

Using processes Looking at the output from a couple of ps commands that can detect the various versions of systemd & upstart, which could be crafted like so: upstart $ ps -eaf|grep '[u]pstart' root 492 1 0 Jan02 ? 00:00:00 upstart-udev-bridge --daemon root 1027 1 0 Jan02 ? 00:00:00 upstart-socket-bridge --daemon ...


18

killing 0 isn't killing the pid 0. Instead it is an option in kill to kill all processes in the current group. With your command you are killing everything in the process group ID (GID) of the shell that issued the kill command. from the kill man page: pid... Specify the list of processes that kill should signal. Each pid can be one of five ...


17

Systemd is backward compatible with SysV init scripts. According to LSB 3.1, the init script must have informational Comment Conventions, defining when the script has to start/stop and what is required for the script to start/stop. This is an example: ### BEGIN INIT INFO # Provides: my-service # Required-Start: $local_fs $network $remote_fs # Required-Stop: ...


16

telinit u will restart init without affecting the rest of the system.


16

Try: sudo reboot -f -f, --force Force immediate halt, power-off, reboot. Do not contact the init system. or sudo shutdown -r now


15

If you're not root (and you shouldn't normally be logging in as root), you'll just get a message: bash$ init init: Need to be root if you are root, you can change the current run level of the system using init (it actually runs "telinit" to make the change). bash$ sudo init init: missing runlevel Try `init --help' for more information. if you really want ...


15

As I understand it, a zombie process has died but still exists as a placeholder in the process table until its parent (or init if the zombie is itself an orphan) checks its exit status. Correct. And my understanding of orphan processes is they are processes that are still alive and running but whose parent has died. Correct. Since a zombie is already ...


14

There seems to be no way to log this data to a file. For the boot process, there is the bootlogd package which creates the file /var/log/boot, but nothing for the shutdown/reboot process. As far as I can see there is no way to log with rsyslog either, and even if there was, there are messages printed after rsyslog is stopped. Part of my shutdown/reboot ...


14

I found a wonderful explanation here. However, let me try to put in a shorter format of what I understood in the answer. Shorter Version While the system boots, it needs an early userspace. It can be achieved using either initramfs or initrd. initrd is loaded into ramdisk which is an actual FILE SYSTEM. initramfs is not a file system. For initrd ...


13

If you start in these, the system will shut down/reboot as soon as it enters the runlevel. A runlevel is essentially just a way of specifying actions you want to take when you enter/leave a certain state, in that respect, once those runlevels are entered they execute programs that prepare the computer to shut down or reboot, respectively.


13

init is the conventional name of the program that runs in process #1. It has taken many forms over the years, and the tasks that init programs have performed have significantly varied. Confusingly, it is also the name of a command that administrators use to communicate with process #1. They are best regarded as two separate things, and were certainly ...


12

Not that efficient but I it seems to work. strings /sbin/init | grep -q "/lib/systemd" && echo SYSTEMD strings /sbin/init | grep -q "sysvinit" && echo SYSVINIT strings /sbin/init | grep -q "upstart" && echo UPSTART It will print more lines if more than one strings match, which could be translated to "Can't guess". Strings used in ...


12

The simplest way is to use the su(1) command, it has an option that allows you to run a command via the user's shell, example: su foo -c ls This will switch to the user foo and run the ls command. If the user you want to use does not have a valid shell (ie it's not in /etc/shells, like /bin/false or /sbin/nologin) you will also have to specify a shell on ...


12

When a process exits, all its children also die (unless you use NOHUP in which case they get back to init). This is correct if the process is a session leader. When a session leader dies, a SIGHUP is sent to all members of that session. In practice that means its children and their descendants. A process makes itself session leader by calling setsid. ...


Only top voted, non community-wiki answers of a minimum length are eligible