Hot answers tagged

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


20

The new process will be created within the fork() call, and will start by returning from it just like the parent. The return value (which you stored in retval) from fork() will be: 0 in the child process The PID of the child in the parent process -1 in the parent if there was a failure (there is no child, naturally) Your testing code works correctly; it ...


16

The POSIX 2008 standard has a section describing "Shell and Utilities". Generally, if you stick to that your scripts should be fairly future-proof, except possibly for deprecations, but those hardly happen overnight so you should have plenty of time to update your scripts. In some cases where output format for a single utility varies widely across ...


13

I thought that fork() creates a same process, so I initially that that in that program, the fork() call would be recursively called forever. I guess that new process created from fork() starts after the fork() call? Yes. Let's number the lines: int main (int argc, char **argv) { int retval; /* 1 */ ...


12

I'll try to answer from my experience. Commands don't really adhere to a formal specification, but they do adhere to a requirement to consume and generate line-oriented text. Yes, of course. Before the GNU utilities became a de facto standard, a lot of vendors would have quirky output, especially with respect to ps and ls. This caused a lot of pain. ...


11

To be called UNIX you need to go through a certification process that requires (among other things) that you implement the POSIX standard. So your question is completely invalid. There is UNIX API, it's called POSIX. EDIT: Here is the list of requirements: http://www.unix.org/version4/overview.html


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

First, very brief answers to your questions: Formal standardization of input/output conventions: no Breakage in the past due to changing output: yes Absolutely impossible to break future filters: no How can I protect myself against changes: be conservative When you say "API", you're using a term that (for good or ill) implies too much formality around ...


8

Open() offers a way to lock files while they are in use. If files were automatically opened, read/written and then closed again by the OS there would be nothing to stop other applications changing those files between operations. While this can be manageable (many systems support non-exclusive file access) for simplicity most applications assume that files ...


7

Why does *BSD uses driver specific names for network interfaces? It's just a historical choice. The letters in the name come from the driver that talks to the card, so they will be the same for two separate interfaces if they happen to use the same driver. It does have one practical benefit: on BSD, the network drivers have their own manual pages in ...


6

ntfs-3g can read alternate data streams in NTFS. From its manpage: Alternate Data Streams (ADS) NTFS stores all data in streams. Every file has exactly one unnamed data stream and can have many named data streams. The size of a file is the size of its unnamed data stream. By default, ntfs-3g will only read the ...


6

You're leaving a zombie, trivially, because you didn't wait on your child process. Your shell is immediately exiting because you've set up its STDIN in a nonsensical way. pipe returns a one-way communications channel. You write to pipefd[1] and read it back from pipefd[0]. You did a buch of dup2 calls which lead the shell to attempt to read (STDIN) from the ...


5

It really seems to me that the Unix community is killing themselves in the Desktop world. I think there is a misconception that any form of Unix exists in order to compete in the home PC market. There are some linux distros which have this focus; the first one was really Ubuntu, but it is worth considering that part of Ubuntu's original vision was to ...


5

The choice of using generic or driver-specific names has nothing to do with any driver limitation. It's mostly a cosmetic choice. Using generic names has the advantage of hiding information that is almost always irrelevant — a network interface is a network interface, no matter who made it. The capabilities of a device depend on the exact model and on its ...


5

A new file descriptor always occupies the lowest integer not already in use. $ cat >test.c main(){exit(open("/dev/null",0));} ^D $ cc test.c $ ./a.out; echo $? 3 $ ./a.out <&-; echo $? 0 $ ./a.out >&-; echo $? 1 The system doesn't care about "standard file descriptors" or anything like that. If file descriptor 0 is closed, then a new ...


5

Because the file's path might move while you're assuming it will stay the same.


4

Only covering 1) of your question. Naturally APIs can always change at the will of their creators, and thusly break dependent software, in any language. That said, the great idea of the Unix tools' I/O "APIs" is that there is practically none (maybe 0x0a as line end). A good script filters data with the Unix tools instead of creating it. That means that ...


4

If you just want the timezone, then timezones are stored in /usr/share/zoneinfo. If you want to be able to retrieve the current time for a number of different cities or countries, then you can pull them from the Date and Time Gateway.


4

Most hardware devices offer a file-like API. This is done because it makes both the design of the operating system and the design of applications simpler. The OS only has to have a file API and not a separate terminal API and a separate disk API and a separate sound API and so on. Applications that are not using features specific to a particular kind of ...


4

The FS comes from the additional segment register named FS on the 386 architecture (end of second paragraph). My guess is that after DS for Data Segment and ES for Extra Segment Intel just went for the next characters in the alphabet (FS, GS). You can see the 386 register on the wiki page, on the graphic on the right side. From the linux kernel source on ...


4

Reading and writing to a filesystem may involve a large variety of buffering schemes, OS housekeeping, low-level disk management, and a host of other potential actions. So the actions of open() and close() serve as the set-up for these types of under the hood activities. Different implementations of a filesystem could be highly customized as needed and still ...


3

It makes it easier to tell which network card you are talking to. If you have an Intel (igb0) and an Realtek (rl0) nic, you can now tell them apart immediately. Also, different drivers support different features. Some drivers support polling and some do not. Some support LRO, TSO and RSS etc. It is easier to track which support which when they are not all ...


3

Unix has specifications/a standard they hope you'll follow, POSIX, ways things should be implemented, though up to the developer, it's a standard we should follow if we want our code to work on many architectures/platforms/systems whatever, up to the developer at the end of the day to follow what (hopefully) majority of developers are following. Windows has ...


3

You can simply do something like this: $ TZ=Europe/Moscow date Thu Jun 9 08:34:46 MSD 2011 $ TZ=America/NewYork date Thu Jun 9 04:34:48 America 2011 You can find the zone names in /usr/share/zoneinfo. Of course, this requires that the machine you run this on has the correct time set. (You can't really get the time by country, because a lot of countries ...


2

strace can give you a picture of what your executable is doing with file descriptors: strace -f -e trace=file,desc,ipc -o /tmp/strace.txt /path/to/exe arg1 arg2...


2

The FOSS scanner/imaging API is SANE. You may need to install Linux compatibility files in order to allow it to access the webcam as a V4L device.


2

You can use Netlink. From the wiki, Netlink was designed for and is used to transfer miscellaneous networking information between the Linux kernel space and user space processes. Networking utilities such as iproute2 use Netlink to communicate with the Linux kernel from user space. Netlink consists of a standard socket-based interface for user ...


2

gnome-weather uses libgweather underneath which in turn uses several GWeatherProviders (defined in gweather-weather.h) to get weather information for your particular geo-location: * GWeatherProvider: .... * @GWEATHER_PROVIDER_METAR: METAR office, providing current conditions worldwide * @GWEATHER_PROVIDER_IWIN: US weather office, providing 7 days of ...



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