Tag Info

Hot answers tagged

19

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


12

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


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


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

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


5

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


4

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


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

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.


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

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


1

Why does *BSD uses driver specific names for network interfaces? To make things simple. If you look to an interface named bge0 and take a look at the manuals or use your mnemonic link system you will quickly remember that this driver is a Broadcom Gigabit Etherhet. This document is also usefull. Does it mean there is no abstraction layer describing ...


1

Netlink. Look into the ss command from the iproute2 collection.


1

Here is a link to libnetfilter_conntrack. You would have to re-write your program in a language that can support calling C functions from a library directly. But I think this library will have the hooks you need to get the data you want much faster than parsing through that text file. This is what the iptstate program uses to accomplish its task.


1

There are only de facto IO standards — whitespace and null separated output. As for compatibility, we usually revert to checking version numbers of individual filters. Not that they change much, but when you want to use a brand new feature and still want the script to run on older versions, you have to "ifdef" it out somehow. There is practically no ...



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