111

There are several different scenarios; I'll describe the most common ones. The successive macroscopic events are: Input: the key press event is transmitted from the keyboard hardware to the application. Processing: the application decides that because the key A was pressed, it must display the character a. Output: the application gives the order to display ...


104

"Everything is a file" is a bit glib. "Everything appears somewhere in the filesystem" is closer to the mark, and even then, it's more an ideal than a law of system design. For example, Unix domain sockets are not files, but they do appear in the filesystem. You can ls -l a domain socket to display its attributes, cat data to/from one, modify its access ...


101

The reason why this is permitted is related to what removing a file actually does. Conceptually, rm's job is to remove a name entry from a directory. The fact that the file may then become unreachable if that was the file's only name and that the inode and space occupied by the file can therefore be recovered at that point is almost incidental. The name of ...


70

In short: If you're taking a compiled binary from one host to another using the same (or a compatible) architecture, you may be perfectly fine taking it to another distribution. However as complexity of the code increases, the likelihood of being linked against a library that is not installed; installed in another location; or installed at a different ...


65

The short answer is, fork is in Unix because it was easy to fit into the existing system at the time, and because a predecessor system at Berkeley had used the concept of forks. From The Evolution of the Unix Time-sharing System (relevant text has been highlighted): Process control in its modern form was designed and implemented within a couple of days. ...


60

Dennis Ritchie mentions in «The Evolution of the Unix Time-sharing System» that open and close along with read, write and creat were present in the system right from the start. I guess a system without open and close wouldn't be inconceivable, however I believe it would complicate the design. You generally want to make multiple read and write calls, not ...


59

dpkg --print-architecture will output the primary architecture of the machine it's run on. This will be armhf on a machine running 32-bit ARM Debian or Ubuntu (or a derivative), arm64 on a machine running 64-bit ARM. Note that the running architecture may be different from the hardware architecture or even the kernel architecture. It's possible to run i386 ...


54

Then all of the read and write calls would have to pass this information on each operation: the name of the file the permissions of the file whether the caller is appending or creating whether the caller is done working with the file (to discard unused read-buffers and ensure write-buffers really finished writing) Whether you consider the independent calls ...


51

The concept of the file handle is important because of UNIX's design choice that "everything is a file", including things that aren't part of the filesystem. Such as tape drives, the keyboard and screen (or teletype!), punched card/tape readers, serial connections, network connections, and (the key UNIX invention) direct connections to other programs called "...


50

It depends. Something compiled for IA-32 (Intel 32-bit) may run on amd64 as Linux on Intel retains backwards compatibility with 32-bit applications (with suitable software installed). Here's your code compiled on RedHat 7.3 32-bit system (circa 2002, gcc version 2.96) and then the binary copied over to and run on a Centos 7.4 64-bit system (circa 2017): -...


39

No, kernels from different implementations of Unix-style operating systems are not interchangeable, notably because they all present different interfaces to the rest of the system (user space) — their system calls (including ioctl specifics), the various virtual file systems they use... What is interchangeable to some extent, at the source level, is the ...


37

That entirely depends on what services you want to have on your device. Programs You can make Linux boot directly into a shell. It isn't very useful in production — who'd just want to have a shell sitting there — but it's useful as an intervention mechanism when you have an interactive bootloader: pass init=/bin/sh to the kernel command line. All Linux ...


36

The 50,000 foot view is that: A signal is generated either by the kernel internally (for example, SIGSEGV when an invalid address is accessed, or SIGQUIT when you hit Ctrl+\), or by a program using the kill syscall (or several related ones). If it’s by one of the syscalls, then the kernel confirms the calling process has sufficient privileges to send the ...


36

[I'll repeat part of my answer from here.] Why not just have a command that creates a new process from scratch? Isn't it absurd and inefficient to copy one that is only going to be replaced right away? In fact, that would probably not be as efficient for a few reasons: The "copy" produced by fork() is a bit of an abstraction, since the kernel uses a copy-...


35

Originally you had just dumb terminals - at first actually teletypewriters (similar to an electric typewriter, but with a roll of paper) (hence /dev/tty - TeleTYpers), but later screen+keyboard-combos - which just sent a key-code to the computer and the computer sent back a command that wrote the letter on the terminal (i.e. the terminal was without local ...


33

Run dpkg --get-selections | awk '/i386/{print $1}' And then if happy with them being removed, run apt-get remove --purge `dpkg --get-selections | awk '/i386/{print $1}'` And then retry the dpkg --remove-architecture i386


32

When you “open a terminal”, you're starting a terminal emulator program, such as xterm, gnome-terminal, lxterm, konsole, … One of the first things the terminal emulator does is to allocate a pseudo terminal (often called a pseudo-tty, or pty for short). The pty is a pair of character device files: the pty master, which is the side that the terminal emulator ...


31

You can determine the nature of an executable in Unix using the file command and the type command. type You use type to determine an executable's location on disk like so: $ type -a ls ls is /usr/bin/ls ls is /bin/ls So I now know that ls is located here on my system in 2 locations:/usr/bin/ls & /bin/ls. Looking at those executables I can see they're ...


25

Adding to the excellent @thrig and @DopeGhoti answers: Unix or Unix-like OSes, including Linux, were traditionally always designed and aligned more for the portability of source code than binaries. If having nothing hardware specific or being a simple source as in your example, you may move it without any problem at all from between pretty much any version ...


25

First, why there are separate /lib and /lib64: The Filesystem Hierarchy Standard mentions that separate /lib and /lib64 exist because: 10.1. There may be one or more variants of the /lib directory on systems which support more than one binary format requiring separate libraries. (...) This is commonly used for 64-bit or 32-bit support on systems ...


23

Signal implementation is very complex and is kernel specific. In other words, different kernels will implement signals differently. A simplified explanation is as follows: The CPU, based on a special register value, has an address in memory where it expects to find an "interrupt descriptor table" which is actually a vector table. There is one vector for ...


22

The reason is that the lib/lib64 directories can contain files which happen to have the same name because those are libraries shared with diverse programs. Putting them in separate directories solves the conflict. There's (usually...) no good reason for distributing same-named executables on the same system which are 32/64-bit, but since there can be a ...


20

I checked uname manual (man uname) and it says the following for the "-a" option: print all information, in the following order, except omit -p and -i if unknown In Ubuntu, I guess, options "-m", "-p" and "-i" (machine, processor and hardware-platform) are returning the machine architecture. For example, if you use the command uname -mpi You will see:...


20

By default, you'll almost certainly run into problems with external libraries. Some of the other answers go into more details about those problems, so I won't duplicate their work. You can, however, compile many programs - even non-trivial ones - to be portable between Linux systems. The key is toolkit called the Linux Standard Base. The LSB is designed ...


19

Conceptually, a library function is part of your process. At run-time, your executable code and the code of any libraries (such as libc.so) it depends on, get linked into a single process. So, when you call a function in such a library, it executes as part of your process, with the same resources and privileges. It's the same idea as calling a function you ...


17

Though this question has been answered, let me post a detailed flow of events in Linux kernel. This is copied entirely from Linux posts: Linux Signals - Internals at the “Linux posts” blog at sklinuxblog.blogspot.com. Signal User Space C Program Let’s start with writing a simple signal user space C program: #include<signal.h> #include<stdio.h> ...


16

Here are the answers to your questions: I'd view it as a graphical image rather than an ASCII image. $ lstopo --output-format png -v --no-io > cpu.png NOTE: You can view the generated file cpu.png                       "PU P#" = Processing Unit ...


14

You don't need much bash code to implement classes or objects in bash. Say, 100 lines. Bash has associative arrays that can be used to implement a simple Object system with inheritance, methods and properties. So, you would might define a class like this: class Queue N=10 add=q_add remove=q_remove Creating an instance of this Queue might be done like ...


14

Because of how waitpid works. On a POSIX system, a signal (SIGCHLD) is delivered to a parent process when one of its child processes dies. At a high level, all waitpid is doing is blocking until a SIGCHLD signal is delivered for the process (or one of the processes) specified. You can't wait on arbitrary processes, because the SIGCHLD signal would never ...


11

Adding to Useless' answer: Library functions are faster than system calls, and usually do not contain permission/security considerations, as they are running with the process' privileges and it's memory. Syscalls on the other hand, since they run in the kernel, have access to everything in the system, and so they need to control what the calling process can ...


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