12

While I was listening to music I changed the virtual console using Ctrl+Alt+F2, and suddenly the music was paused. Returning back to the console that runs the X server Ctrl+Alt+F7 or logging in to the user in the console that I'm currently using (Ctrl+Alt+F2), starts playing the music again.

Linux (I am using Ubuntu) is a multi-user operating system. As far as I know, it has 7 virtual consoles that users can log on to and work simultaneously. So why is this happening? What would happen if my system was updating while switching the consoles?

2

3 Answers 3

5

Linux has multiple virtual consoles. Ctrl+Alt+Fn switches between these consoles. When you switch from console 7 to console 2, the input and output peripherals are re-routed from console 7 to console 2. When console 7 is inactive, it has no access to the input/output peripherals: the display isn't shown on the screen, the applications don't receive keyboard input, etc.

For historical reasons, sound input and output uses completely different channels from input devices such as keyboard and mouse and from video displays. Console devices (the abstraction in the operating system) cover keyboard and video but not sound. The most common basic implementation of sound on a Unix system is independent from that system, and permission to use the sound peripherals is granted based on group membership rather than on ownership of the console. This is in fact a design deficiency.

Ubuntu has set things up so that the session logged into the console, and only them, has access to the audio device. If you switch consoles, you lose access to the audio device, unless you also log into that other console. This is what really should have been done from the start, but wasn't because the designers of console interfaces weren't thinking about sound.

When you switch to another console, your programs keep running, because the CPU is not associated with a console but with a machine: anyone with an account on the machine is allowed to use CPU time. The same goes for other resources such as memory and files (subject to permissions). It's only interactions with the user that are governed by console ownership. Your sound stops playing when you switch to a console where you aren't logged in because your programs lose the privilege to access the sound output device.

I believe that Ubuntu implements access control via Polkit, but I don't know exactly how this works.

2
  • 1
    You can try this. Play a music and switch the VT. After some time switch back to F7 VT. The song starts from exactly the point where it is paused. How is this possible if system is not sleeping threads. Not giving access to sound I/O can not pause the player. And i tried it while installing a program as well. surprisingly, the program had been installed even when i was switched the VT.
    – DScript
    Jun 25, 2015 at 3:04
  • 2
    @DScript The player thread is blocked because it's waiting for the sound system. A thread that isn't waiting for the sound system continues to run. Not giving access to sound I/O does block the player, because the way it's done is not to deny the request but to block it. Jun 25, 2015 at 10:03
1

A while back, people used computer terminals to input data into, or display data from, a Unix mainframe. If any of this terminal users wanted to, let's say, cat /dev/zero, the output was not broadcasted to all terminals/users connected to the same mainframe (that's because it was a multi user system, and each user could run it's tasks without affecting other users).

In our days, we're using virtual terminals (or virtual consoles - VC) that are software emulations of the physical computer terminals, and work in a similar way. If you're logged in on VC1 and run ls -alR /, the output will not be broadcasted to all VCs, and, even if you switch to another VC, your ls will keep running in VC1 and send it's output to VC1 (the same way, your update command will keep running in the VC you started it even if you switch to another VC).

Now, sound it's a bit different than standard output, as (by default) it uses the same device for output no matter the VC your user is logged in into, but your user has to be logged in to have access to the output of the sound device.

You can also have a look here for some more details regarding VC.

2
  • 1
    You can try this. Play a music and switch the VT. After some time switch back to F7 VT. The song starts from exactly the point where it is paused. How is this possible if system is not sleeping threads. Not giving access to sound I/O can not pause the player. And i tried it while installing a program as well. surprisingly, the program had been installed even when i was switched the VT.
    – DScript
    Jun 25, 2015 at 3:09
  • 1
    @DScript that's because the player you are using was designed to detect switching to another VC and pause. By default, the system will not nice or pause processes when switching to another VC.
    – petry
    Jun 25, 2015 at 3:29
1

Try

usermod -a -G audio youruser

From: https://www.reddit.com/r/linux/comments/1ckvhd/keeping_music_playing_across_multiple_terminal/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.