Archive for the ‘linux’ Category

How to match an empty line in grep

Friday, May 14th, 2010

I forgot that grep is different than regex in PHP. grep is automatically line oriented, so if you are trying to find an empty line, there is no point trying to match against the newline character (”\n”). Instead, when you need to find an empty line with grep, you do this:

grep -v “^$” filename

Someday Linux might be a real platform for music mixing

Wednesday, September 23rd, 2009

I’ve been frustrated with the sound on my Ubuntu machine. It is fine when it boots up, but only one app at a time can use the speakers (I understand that there are patches for this. I’ve been too lazy to install them. The point is the issue isn’t resolved by default, as it is on Mac and Windows machines). And often an app will quit but not release its hold of the speakers, so the only way I can get them working again is to reboot the machine.

Therefore, I am pleased to know that sound is getting better on Linux. I had no idea most of this software existed. Examples:

Lash uptake has been good, and now lash talks dbus… letting it mix in nicely with the rest of the linux desktop ecosystem. Lash is a session system for linux audio programs. It lets you open your 12 different linux audio programs(remember audio in linux is like pipes… pipes with audio running through them instead of water… let’s call them wires… but digital… maybe fiber optics… but not using light… ok whatever… why am I explaining it this way?… you’re not five… too many dots. sorry.) and save your settings for later. The alternative is to each time open your 12 programs, set up the wiring between six of them, start messing around and finally… 2 hours later… realise you were supposed to be setting them up in a certain way rather than making stupid minimal beep noises to a house vocals mixed with a recording of a fart noise – filtered down to retro 8bit samples. Without lash, you couldn’t save that brilliant setup and play with it later.

Audacity, the simple(yet advanced) audio editing work horse is moving towards a 2.0 by the end of the year. Audacity has been around for ages, and has been multi platform for ages. The 1.3 series seems to have been going on forever… but they do regular beta releases, and nightly builds. So it’s pretty easy to get fresh versions. Do proper releases matter that much when new releases are pushed out every day? I guess so.

How to track which programmers contribute to a project

Monday, September 21st, 2009

I’ve worked on projects with 8 or 9 programmers and the managers running the project had no idea which programmers were contributing what. I have often been surprised that some managers are willing to fly in the dark, regarding who is doing what. These tend to be managers with weak technical backgrounds, so perhaps they are unable to analyze the work at the appropriate level.

This analysis of who contributes to Linux seems full of information that managers would want to track about any project:

Beyond that, how one generates statistics from a patch stream is an
interesting question. How does one measure the productivity of
programmers? One possibility is to look at the number of changesets
merged. By that metric, this is the list of the most prolific contributors
to 2.6.20:

Developers with the most changesets
Al Viro 241 4.8%
Andrew Morton 92 1.8%
Jiri Slaby 92 1.8%
Adrian Bunk 87 1.7%
Gerrit Renker 79 1.6%
Josef Sipek 79 1.6%
Avi Kivity 68 1.4%
Tejun Heo 67 1.3%
Patrick McHardy 63 1.3%
Ralf Baechle 61 1.2%
Randy Dunlap 59 1.2%
Alan Cox 58 1.2%
Mariusz Kozlowski 57 1.1%
Andrew Victor 53 1.1%
Paul Mundt 52 1.0%
Stefan Richter 49 1.0%
David S. Miller 48 1.0%
Russell King 44 0.9%
Benjamin Herrenschmidt 44 0.9%
Akinobu Mita 43 0.9%

Looking at patch counts rewards developers who put in large numbers of
small patches. Al Viro’s patches include a vast number of code annotations
(to enable better checking with sparse), include file fixups,
etc. Many of the changes are small – many do not affect the resulting
kernel executable at all – but there are a lot of them. Even so, as the
biggest contributor, Al generated less than 5% of the
total changesets added to the kernel. The top 20 contributors, all
together, generated 28% of the total changesets in 2.6.20.

One could make the argument that a better way to look at the problem is by
the number of lines affected by a patch. In this way, a contributor’s
portion of the whole will not depend on whether it has been split into a
long series of small patches or not. On the other hand, simply renaming a
file can make it look like a developer has touched a large amount of code.
Be that as it may, by looking at lines changed (defined
as the greater of the number of lines added or removed by each individual
changeset), one gets a table like this:

Developers with the most changed lines
Jeff Garzik 20712 6.0%
Patrick McHardy 15024 4.3%
Jiri Slaby 13917 4.0%
Avi Kivity 11726 3.4%
Andrew Victor 9710 2.8%
Amit S. Kale 9537 2.7%
Stephen Hemminger 9120 2.6%
Geoff Levand 8396 2.4%
Michael Chan 8307 2.4%
Chris Zankel 8099 2.3%
Mauro Carvalho Chehab 7390 2.1%
Adrian Bunk 6138 1.8%
Yoshinori Sato 5232 1.5%
Al Viro 4981 1.4%
Benjamin Herrenschmidt 4588 1.3%
Thierry MERLE 4549 1.3%
Dan Williams 4516 1.3%
Jonathan Corbet 3924 1.1%
Gerrit Renker 3857 1.1%
Jiri Kosina 3805 1.1%

Gparted for Linux partitions

Friday, September 11th, 2009

Gparted: a very useful utility for dealing with Linux partitions and hard drives.

btfs

Sunday, August 2nd, 2009

Yesterday I learned about ZFS. Apparently there is a file system called btfs, which bring some of the same features to Linux:

Imagine you are a Linux file system developer. It’s 2007, and you are at the Linux Storage and File systems workshop. Things are looking dim for Linux file systems: Reiserfs, plagued with quality issues and an unsustainable funding model, has just lost all credibility with the arrest of Hans Reiser a few months ago. ext4 is still in development; in fact, it isn’t even called ext4 yet. Fundamentally, ext4 is just a straightforward extension of a 30-year-old format and is light-years behind the competition in terms of features. At the same time, companies are clamping down on funding for Linux development; IBM’s Linux division is coming to the end of its grace period and needs to show profitability now. Other companies are catching wind of an upcoming recession and are cutting research across the board. They want projects with time to results measured in months, not years.

Ever hopeful, the file systems developers are meeting anyway. Since the workshop is co-located with USENIX FAST ‘07, several researchers from academia and industry are presenting their ideas to the workshop. One of them is Ohad Rodeh. He’s invented a kind of btree that is copy-on-write (COW) friendly [PDF]. To start with, btrees in their native form are wildly incompatible with COW. The leaves of the tree are linked together, so when the location of one leaf changes (via a write – which implies a copy to a new block), the link in the adjacent leaf changes, which triggers another copy-on-write and location change, which changes the link in the next leaf… The result is that the entire btree, from top to bottom, has to be rewritten every time one leaf is changed.

Rodeh’s btrees are different: first, he got rid of the links between leaves of the tree – which also “throws out a lot of the existing b-tree literature”, as he says in his slides [PDF] – but keeps enough btree traits to be useful. (This is a fairly standard form of btrees in file systems, sometimes called “B+trees”.) He added some algorithms for traversing the btree that take advantage of reference counts to limit the amount of the tree that has to be traversed when deleting a snapshot, as well as a few other things, like proactive split and merge of interior nodes so that inserts and deletes don’t require any backtracking. The result is a simple, robust, generic data structure which very efficiently tracks extents (groups of contiguous data blocks) in a COW file system. Rodeh successfully prototyped the system some years ago, but he’s done with that area of research and just wants someone to take his COW-friendly btrees and put them to good use.

Very cool technology in OpenSolaris

Friday, July 31st, 2009

I’ve always been happy with Linux on the server, and I’ve never felt any need to experiment with OpenSolaris, until I read this bit about ZFS:

ZFS is the most amazing filesystem I’ve ever come across. Integrated volume management. Copy-on-write. Transactional. End-to-end data integrity. On-the-fly corruption detection and repair. Robust checksums. No RAID-5 write hole. Snapshots. Clones (writable snapshots). Dynamic striping. Open source software. It’s not available on Linux. Ugh. Ok, that sucks. (GPL is a double-edged sword, and this is a perfect example). Since it’s open-source, it’s available on other OSes, like FreeBSD and Mac OS X, but Linux is a no go. *sigh* I have a feeling Sun is working towards GPL’ing ZFS, but these things take time and I’m sick of waiting.

The OpenSolaris project is working towards making Solaris resemble the Linux (GNU) userland plus the Solaris kernel. They’re not there yet, but the goal is commendable and the package management system has taken a few good steps in the right direction. It’s still frustrating, but massively less so. Despite all the rough edges, though, ZFS is just so compelling I basically have no choice. I need end-to-end data integrity. The rest of the stuff is just icing on an already delicious cake.

The difference between Windows programmers and Unix programmers

Sunday, July 12th, 2009

I stumbled upon this old post by Joel Spolsky:

What’s left is cultural differences. Yes, we all eat food, but over there, they eat raw fish with rice using wood sticks, while over here, we eat slabs of ground cow on bread with our hands. A cultural difference doesn’t mean that American stomachs can’t digest sushi or that Japanese stomachs can’t digest Big Macs, and it doesn’t mean that there aren’t lots of Americans who eat sushi or Japanese who eat burgers, but it does mean that Americans getting off the plane for the first time in Tokyo are confronted with an overwhelming feeling that this place is strange, dammit, and no amount of philosophizing about how underneath we’re all the same, we all love and work and sing and die will overcome the fact that Americans and Japanese can never really get comfortable with each others’ toilet arrangements.

…What are the cultural differences between Unix and Windows programmers? There are many details and subtleties, but for the most part it comes down to one thing: Unix culture values code which is useful to other programmers, while Windows culture values code which is useful to non-programmers.

…The cultural schism is so sharp that Unix has never really made any inroads on the desktop. Aunt Marge can’t really use Unix, and repeated efforts to make a pretty front end for Unix that Aunt Marge can use have failed, entirely because these efforts were done by programmers who were steeped in the Unix culture. For example, Unix has a value of separating policy from mechanism which, historically, came from the designers of X. This directly led to a schism in user interfaces; nobody has ever quite been able to agree on all the details of how the desktop UI should work, and they think this is OK, because their culture values this diversity, but for Aunt Marge it is very much not OK to have to use a different UI to cut and paste in one program than she uses in another. So here we are, 20 years after Unix developers started trying to paint a good user interface on their systems, and we’re still at the point where the CEO of the biggest Linux vendor is telling people that home users should just use Windows. I have heard economists claim that Silicon Valley could never be recreated in, say, France, because the French culture puts such a high penalty on failure that entrepreneurs are not willing to risk it. Maybe the same thing is true of Linux: it may never be a desktop operating system because the culture values things which prevent it. OS X is the proof: Apple finally created Unix for Aunt Marge, but only because the engineers and managers at Apple were firmly of the end-user culture (which I’ve been imperialistically calling “the Windows Culture” even though historically it originated at Apple).

…There are too many monocultural programmers who, like the typical American kid who never left St. Paul, Minnesota, can’t quite tell the difference between a cultural value and a core human value. I’ve encountered too many Unix programmers who sneer at Windows programming, thinking that Windows is heathen and stupid. Raymond all too frequently falls into the trap of disparaging the values of other cultures without considering where they came from. It’s rather rare to find such bigotry among Windows programmers, who are, on the whole, solution-oriented and non-ideological. At the very least, Windows programmers will concede the faults of their culture and say pragmatically, “Look, if you want to sell a word processor to a lot of people, it has to run on their computers, and if that means we use the Evil Registry instead of elegant ~/.rc files to store our settings, so be it.” The very fact that the Unix world is so full of self-righteous cultural superiority, “advocacy,” and slashdot-karma-whoring sectarianism while the Windows world is more practical (”yeah, whatever, I just need to make a living here”) stems from a culture that feels itself under siege, unable to break out of the server closet and hobbyist market and onto the mainstream desktop.

I disagree with his defense of Windows. While there are many fantastic Windows programmers, brilliance is not what this culture is about. Spolsky puts the best face on it when he says “…Windows programmers, who are, on the whole, solution-oriented and non-ideological.” One has to be careful when generalizing about so many people, but I think the average Windows programmer doesn’t really care about programming. To say they are “non-ideological” is to put a positive spin on apathy.

Spolsky is exactly right when he sums up Windows programmers as having this attitude: “yeah, whatever, I just need to make a living here”. That is the attitude that I see everywhere when looking at Windows programmers. In general, people who go into Windows programming tend to simply be in it for the money. People who are, instead, attracted to Unix or Linux tend to be people who really care about the art of programming. Because of this, software built using .NET often sucks, whereas code written on Unix/Linux platforms is often very good.

Look at the best known web sites built various technologies: MySpace was built with .NET and it is a permanent disaster, always full of bugs. Meanwhile, Facebook was written in PHP on a Unix stack, and its architecture is so beautiful that they write about it in books called Beautiful Architecture.

Again, I’ll repeat, there are a lot of great Windows programmers, and you can write great software using .NET. However, overall, I think the Windows platform attracts people who simply want a job, and their lack of concern about quality is reflected in the code they churn out. By comparison, the Unix/Linux platform tends to attract people who care passionately about the quality of the code they write, so the software on this platform tends to be of a better quality.

So frustrated with Mozilla that I’ve got a sore throat from yelling

Monday, June 8th, 2009

FireFox can crash any machine. Not “crash” in the sense of “blue screen of death” but crash as in “uses up all memory so the machine becomes unresponsive”. This is a reliable fact of using FireFox, regardless of whether you are on Ubuntu Linux, Windows XP, or Mac OS X (I can’t speak of Camino, as I don’t use it).

Sometimes I say this to other programmers and they respond “It’s not FireFox that is the problem, it is the plugins that you use – it is FireBug and Session Manager and all the others.” Of course, any programmer who reveals this attitude needs to be re-educated. If you offer a plugin system that is unable to manage the plugins, then maybe you should not offer that plugin system? It suggests a (possibly frightening?) willingness to shirk responsibility if a programmer defends a plugin system that can crash a computer.

I wonder what Brendan Eich is thinking?

One suggestion for others: if you use FireFox, every time a new version of FireFox comes out, FireFox will ask you if you want to upgrade. I used to always say “yes”. Now I realize, if your computer is more than a year old, you should say “no”. Each version of FireFox tends to be heavier and slower than the previous version. My Ubuntu machine is from 2006, and that is part of the reason why FireFox is so slow on it.

On my Windows machine, I just switched over to Google Chrome as my new default browser. I’m giving up on FireFox. On my Ubuntu machine, I am stuck with FireFox for now. I’m not aware of any other serious browsers for Linux.

For email, I would love to give up on Thunderbird, if I could find a substitute. I run Thunderbird on my main desktop machine which runs Ubuntu. Thunderbird has had a persistent bug that has survived several upgrades (of both Thunderbird and Ubuntu). The bug is with the address auto-completion. If I type an address fast, hit “Enter” to accept and start typing again fast, Thunderbird crashes. This can lose a lot of work for me (Where “work” might simply mean “Opened email and left them open because I found some that were important and so answering them will take some time.”). Apparently there is no equivalent of SessionManager for Thunderbird, no way of remembering which emails were open, waiting for a response, when Thunderbird crashes. No, instead, after Thunderbird crashes, I need to re-start it, go back 3 days, and then read through all my email again, looking for the important ones.

At work we had a deadline today, and I worked through the weekend to meet it. I kept getting feedback from various people testing the site. Some of the email I got was thoughtful, and offered intelligent suggestions about what we should do next. By this morning, I had about 20 emails open, waiting for me to have the time and focus to write a reply. Then Thunderbird crashed and they all vanished. I yelled so loud my throat was sore. Now I have to go back to Friday and read through all the email again, to find the ones that I wanted to respond to.

If I could find something better than Thunderbird, that runs on Linux, I’d switch immediately.

What does the Linux file system look like?

Monday, May 19th, 2008

What does the classic Linux file system look like. This is the best diagram I’ve ever seen.

Plesk can be a pain

Friday, November 16th, 2007

I had to do some system administration on the company server yesterday. I’ve two things to note.

1.) This is a nice list of commands for user management.

2.) Plesk makes normal system administration a nightmare. It sets up its own config files that override the defaults for most of the software on a Linux system. While Plesk makes some tasks easy for non-technical people, it makes normal system administration (where you ssh to the server) a real pain. You can follow some tutorial exactly, like the directions for adding a user on this page, and your work has no effect. Last night I was able to set up a user account, but was not able to set a working password. Turns out the passwords were controlled by Plesk.

[Added later:] Okay, I’m an idiot. I was trying to create a user account like this:

useradd -groot -Gadm,wheel,psacln -s/bin/bash -p947364 -d/home/lawrence -m lawrence

The helpful tech staff at RackSpace wrote (in reply to my question) that this command expects the password to be encrypted. So the correct way to add a user (at least on a RackSpace server running RedHat Linux) is as follows:

1.) ssh to the server using some non-root account

2.) after you log in, su to root

3.) run the above command without the password

4.) then run this command:

passwd lawrence

5.) then type in the password you want for the user “lawrence”

System Administration basics

Wednesday, July 25th, 2007

System administration is not my strong point. However, today I had to create some users and groups on a Redhat Linux box that serves websites for Bluewall. I was lucky to find a helpful tutorial, however, when I tried to run the commands as it describes, I ran into this problem:

[root@www httpdocs]# groupadd devteam
bash: groupadd: command not found

Command not found? How could that be? I asked my friend Chris Clarke about this, as he knows more about sysadmin that I do. He wrote back:

Try ‘/usr/sbin/useradd’

If that doesn’t work: ‘updatedb’ then ‘locate *useradd’

His first suggestion was what I needed. This worked perfectly:

[root@www httpdocs]# /usr/sbin/groupadd devteam