Tag Archive for 'Linux'

exec

  • english
  • spanish

exec is a built-in shell command that forces a binary to be executed by the currently running shell process instead of forking the process and running the binary on that child process.

When you run a command on a shell-script, it forks a child process and runs the command there. On a syscall level this is the classic:

if( (pid=fork()) == 0) { exec(command); exit(); } wait();

And this is usually what we want, because we will keep running commands after that one. Nevertheless, sometimes this is a problem, like when:

  • we have a program that’s going to monitor a given process, and it doesn’t run properly if there’s an intermediate shell process but we need to run this second process via a shel-script for whatever reasons (to initialize some variables, run the program with nice, whatever)
  • on MacOS we’re running a program via a shell-script and get two icons on the dock, one for the shell and another one for the program

Running a command with exec forces the shell not to fork, but to run the command directly over the shell process. An important thing to note here is that the shell-script will end there, no further commands of the shell script will be executed as the shell process will be substituted by the command process, so to speak.

#!/bin/sh # initialize variables, parse command-line parameters, etc. export IP=$1 exec nice command $*

My new server

  • english
  • spanish

Ladies and gentleman, let me please introduce you to my new server, the one I’ve been blogging about lately:

dscf0042.JPG dscf0044.JPG

What? You don’t see it? Yes! The small grey box on top of the iomega disk, slightly bigger than the Fonera

In case you don’t know it yet, it’s a Linksys NSLU2, a small device around $100 that comes with two USB2 ports and an ethernet connection. Plug an external USB hard drive to it and it’ll become available over the network like a NAS share. And the best part is: you can flash its firmware and install Debian!! :-D

It’s not that powerful, it has an XScale (ARM) processor at 266Mhz and only 32Mb of RAM. There are pages explaining how to install up to 256Mb. Nevertheless, it works and is small, doesn’t make noise, and has a small electrical consumption.

Up to now I’m running the following on it and it works quite well:

top-nslu2.png

# cat /proc/cpuinfo Processor : XScale-IXP42x Family rev 2 (v5l) BogoMIPS : 266.24 Features : swp half fastmult edsp CPU implementer : 0x69 CPU architecture: 5TE CPU variant : 0x0 CPU part : 0x41f CPU revision : 2 Cache type : undefined 5 Cache clean : undefined 5 Cache lockdown : undefined 5 Cache format : Harvard I size : 32768 I assoc : 32 I line length : 32 I sets : 32 D size : 32768 D assoc : 32 D line length : 32 D sets : 32 Hardware : Linksys NSLU2 Revision : 0000 Serial : 0000000000000000 # free total used free shared buffers cached Mem: 29988 28988 1000 0 404 4808 -/+ buffers/cache: 23776 6212 Swap: 979924 41164 938760 # uname -a Linux eliza 2.6.18-6-ixp4xx #1 Tue Feb 12 00:57:53 UTC 2008 armv5tel GNU/Linux # pstree init-+-afpd---afpd |-atalkd |-atd |-avahi-daemon---avahi-daemon |-cnid_metad |-cron |-dbus-daemon |-events/0 |-getty |-khelper |-klogd |-ksoftirqd/0 |-kthread-+-aio/0 | |-kblockd/0 | |-khubd | |-3*[kjournald] | |-kmirrord | |-kpsmoused | |-kseriod | |-kswapd0 | |-2*[pdflush] | |-scsi_eh_0 | `-usb-storage |-mtdblockd |-nmbd |-papd |-portmap |-rpc.statd |-slpd |-smbd---smbd |-sshd---sshd---sshd---bash---su---bash---pstree |-svscanboot-+-readproctitle | `-svscan-+-supervise---dnscache | |-3*[supervise---multilog] | |-supervise---tinydns | `-supervise---mlnet---mlnet---mlnet |-syslogd `-udevd

Broadcom Wireless on Linux

  • english
  • spanish

At work I have a Dell laptop with a Broadcom BCM94311MCG wireless card:

# lspci ... 0b:00.0 Network controller: Broadcom Corporation BCM94311MCG wlan mini-PCI (rev 01) ... # lspci -n ... 0b:00.0 0280: 14e4:4311 (rev 01) ...

The drivers that Ubuntu installs by default were giving me lots of headaches depending on the network’s access point: on some of them the card worked OK; on some others I kept loosing the connection every few minutes, or I couldn’t connect at all. I never found out if the problem was the encryption algorithm in use, or the wifi a/b/g/whatever protocol. Bottom line is the driver worked on some networks but didn’t on some others.

A co-worker told me he had the same problem until he switched to the ndiswrapper driver, so reluctantly I tried it. It work great. :)
More info here:

Shell-script: timestamp

  • english
  • spanish

A one-liner function that, when piped with the output of another command, prepends each line of that command’s output with a timestamp.

Very useful with commands that output a series of lines periodically but without a timestamp (like vmstat), so that you can’t just send their output to a file and go back to it later without a timeframe.

$ function timestamp { while read l; do d=`date +%H:%M:%S`; echo -e "$d $l"; done; }
$ vmstat 1 | timestamp 12:17:03 procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu---- 12:17:03 r b swpd free buff cache si so bi bo in cs us sy id wa 12:17:03 1 0 4 16740 42816 395164 0 0 6 5 174 11 3 1 96 0 12:17:04 0 0 4 16656 42816 395184 0 0 0 0 393 510 1 1 98 0 12:17:05 0 0 4 16656 42816 395184 0 0 0 0 391 781 2 1 98 0 12:17:06 1 0 4 16656 42824 395176 0 0 0 84 462 976 3 1 95 0 12:17:07 0 0 4 16656 42824 395184 0 0 0 0 433 1545 11 3 86 0 12:17:08 0 0 4 16656 42824 395184 0 0 0 0 356 807 1 2 97 0

ifstat

  • english
  • spanish

ifstat is like some kind of vmstat for network interfaces. Every X seconds, it prints two columns per network interface monitoring the input and output bandwidth.

Quite useful when you need to diagnose a slow network, identify bottlenecks, monitor bandwidth consumption, etc. When invoked with the -t parameter it adds a timestamp on each line, very important if you plan to left it running for hours dumping its output to a file.

# ifstat -t   Time eth0 eth1 HH:MM:SS KB/s in KB/s out KB/s in KB/s out 12:40:25 0.05 0.19 0.00 0.00 12:40:26 0.26 0.24 0.00 0.00 12:40:27 6.87 30.14 0.00 0.00 12:40:28 0.17 0.26 0.00 0.00 12:40:29 0.05 0.22 0.00 0.00 12:40:30 0.05 0.14 0.00 0.00 12:40:31 0.05 0.14 0.00 0.00 12:40:32 0.29 0.38 0.00 0.00 12:40:33 0.29 0.38 0.00 0.00 12:40:34 0.13 0.22 0.00 0.00 12:40:35 2.85 8.70 0.00 0.00 12:40:36 9.01 38.84 0.00 0.00 12:40:37 0.55 0.24 0.00 0.00 12:40:38 0.05 0.14 0.00 0.00

Si te ha interesado, ¿me invitas a una cerveza? / If you liked the post, would you buy me a beer?

Command Line

  • english
  • spanish

I start here a new section on my blog, Command Line (feed), where I will comment on UNIX commands (Linux and MacOS X mainly) that I find useful on my daily work. The articles will range from a very obscure command that I didn’t knew of until some day I needed something like it and found it and saved my day, new or creative ways to use old commands, or small shell-scripts that can make your life easier.

Unless otherwise specified, all these commands are just an “aptitude install” away on Debian and derivate distros (on Ubuntu they may be on universe or multiverse). For RedHat, CentOS, etc. there’s a good chance that you’ll find RPM packages on Dag Wieërs’ repository.

So, without further addo, the first command on the next entry. :)

MacOS X VNC Server

  • english
  • spanish

MacOS X comes with a VNC server, but it has problems: you can’t access it depending on what client version you’re using, and it seems to work only on full-quality mode (32bit color?), so it’s slow like hell.

An alternative is installing the marvelous Vine Server,which on its 3.0 release brings full client/server clipboard integration and works like a charm with any Linux VNC client, fast and without problems.




Creative Commons Attribution-NonCommercial 2.5 Spain
Creative Commons Attribution-NonCommercial 2.5 Spain