Hot answers tagged

88

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 ...


69

A UNIX system consists of several parts, or layers as I'd like to call them. To start a system, a program called the boot loader lives at the first sector of a hard disk partition. It is started by the system, and in turn it locates the Operating System kernel, and load it. Layering The Kernel. This is the central program which is started by the boot ...


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 ...


52

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 ...


51

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 ...


48

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 ...


46

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. ...


39

The tradition in unix tools is to display messages only if something goes wrong. I think this is both for design and practical reasons. The design is intended to make it obvious when something goes wrong: you get an error message, and it's not drowned in not-actually-informative messages. The practical reason is that in unix's very early days, there still ...


34

I can think of three desirable features in a shell: Interactive usability: common commands should be quick to type; completion; ... Programming: data structures; concurrency (jobs, pipe, ...); ... System access: working with files, processes, windows, databases, system configuration, ... Unix shells tend to concentrate on the interactive aspect and ...


32

"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 ...


29

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 ...


22

[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 ...


21

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 ...


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 ...


19

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 ...


19

A hardware interrupt is not really part of CPU multitasking, but may drive it. Hardware interrupts are issued by hardware devices like disk, network cards, keyboards, clocks, etc. Each device or set of devices will have its own IRQ (Interrupt ReQuest) line. Based on the IRQ the CPU will dispatch the request to the appropriate hardware driver. (Hardware ...


19

About your performance question, pipes are more efficient than files because no disk IO is needed. So cmd1 | cmd2 is more efficient than cmd1 > tmpfile; cmd2 < tmpfile (this might not be true if tmpfile is backed on a RAM disk or other memory device as named pipe; but if it is a named pipe, cmd1 should be run in the background as its output can block ...


18

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 ...


15

In the unix world, each tool is designed to do one job and do it well. Why would cp worry about outputting progress when another tool like pv does it already? In the same vein, why do so many programs dump stuff to the screen without any pagination? Because there are already tools for that job such as more (or less). Why do most programs that require editing ...


15

Summary: you're correct that receiving a signal is not transparent, neither in case i (interrupted without having read anything) nor in case ii (interrupted after a partial read). To do otherwise in case i would require making fundamental changes both to the architecture of the operating system and the architecture of applications. The OS implementation ...


14

The directories internal structure is dependent on the filesystem in use. If you want to know precisely what happens, have a look at filesystems implementations. Basically, in most filesystems, a directory is an associative array between filenames(keys) and inodes numbers(values). Something like this¹: 1167010 . 1158721 .. 1167626 subdir 132651 barfile ...


14

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 conceptually the same as calling a ...


14

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


10

I don't think you will get any printed book on this topic. The best resource you should consider is LFS(Linux from Scratch). It is a type of Linux distribution and book which teaches you how to build your own Linux distribution from source.


10

UNIX is a strong OS, build on a sound design that has proven successful for more than 40 years (that's almost eternity in computer science). The central technology is based on the C language and a myriad of small programs: the UNIX commands. The basic philosophy has been summarized by McIlroy: Write programs that do one thing and do it well. Write ...


10

The answer is no, because open() and close() create and destroy a handle, respectively. There are times (well, all of the time, really) where you may want to guarantee that you are the only caller with a particular access level, as another caller (for instance) writing to a file that you are parsing through unexpectedly could leave an application in an ...


9

In order to remove a file, you just need to be able to write to the directory the file is in. If you don't like this, you could set the "sticky" bit via chmod +t dir if you are on a halfway recent OS (this feature was introduced around 1986 in SunOS). If you like to be more fine grained, you need a filesystem with a modern ACL implementaion like ZFS. The ...


9

There are some excellent answers here. However, one thing I think has been left out is how *nix differs from other operating systems, particularly Microsoft Windows. The fundamental concept already covered above "do one thing, do it well" is so central to *nix operating systems that it can sometimes be overlooked. Yet it is this design philosophy that makes ...


9

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 ...


9

Sort of. Check out User-mode Linux.



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