Wednesday, January 25, 2012

prlimit(1)

prlimit(1) is a new util that will be available in util-linux-2.21 (now -rc1). This new util is very nice and flexible command line interface to prlimit(2) Linux syscall (supported since Linux 2.6.36).

prlimit(1) allows to get or set one or more process resource limits for given PID. When a command is given instead of PID, prlimit(1) will run this command with the given resources.

The output is flexible like output from lsblk(8) or findmnt(8). You can define the output columns, use parsable output etc.

See the default output:
  $ prlimit --pid $$
RESOURCE DESCRIPTION SOFT HARD UNITS
AS address space limit unlimited unlimited bytes
CORE max core file size 0 unlimited blocks
CPU CPU time unlimited unlimited seconds
DATA max data size unlimited unlimited bytes
FSIZE max file size unlimited unlimited blocks
LOCKS max number of file locks held unlimited unlimited
MEMLOCK max locked-in-memory address space 65536 65536 bytes
MSGQUEUE max bytes in POSIX mqueues 819200 819200 bytes
NICE max nice prio allowed to raise 0 0
NOFILE max number of open files 1024 4096
NPROC max number of processes 1024 62809
RSS max resident set size unlimited unlimited pages
RTPRIO max real-time priority 0 0
RTTIME timeout for real-time tasks unlimited unlimited microsecs
SIGPENDING max number of pending signals 62809 62809
STACK max stack size 8388608 unlimited bytes
or redefine the output and ask for max number of open files only:
  $ prlimit  --nofile --output RESOURCE,SOFT,HARD --pid $$
RESOURCE SOFT HARD
NOFILE 1024 4096
and now let's modify the soft limit of maximal core file size and maximal number of open files:
  $ prlimit --core=1000000: --nofile=100: --pid $$
the notation used for the limits is:
  soft:hard    specify both limits
soft: specify only the soft limit
:hard specify only the hard limit
value specify both soft and hard limits to the same value
and check the result:
  $ prlimit  --nofile --core --pid $$
RESOURCE DESCRIPTION SOFT HARD UNITS
NOFILE max number of open files 100 1024
CORE max core file size 1000000 unlimited blocks
and revert the core file soft limit:
  $ prlimit --core=unlimited: --pid $$

$ prlimit --core --pid $$
RESOURCE DESCRIPTION SOFT HARD UNITS
CORE max core file size unlimited unlimited blocks
Do you want to restrict CPU time for given command (sort(1) in this example):
   $ prlimit --cpu=10 sort -u hugefile
I think prlimit(1) is much better than the shell built-in command ulimit.

Thanks to Davidlohr Bueso who found time to implement prlimit(1) for util-linux 2.21.
-- In memory of Dennis M. Ritchie

Monday, January 9, 2012

frustrating gnome-control-center network

The "gnome-control-center network" is pretty incomplete application. Unfortunately, this application is called by gnome-shell if you want to modify your network settings. And all this is default in Fedora-16. Grrrr...

The most stupid thing is that you cannot configure wireless connections if your wireless is disabled. And if you enable wireless then you will be affected by your broken configuration...

Fortunately, old good nm-connection-editor works as expected. So, all you need is to kick off the idiotic network stuff from gnome-shell and start old good Network Manager Applet:
 mv /usr/share/gnome-shell/js/ui/status/network.js \
/usr/share/gnome-shell/js/ui/status/network.disabled

and restart gnome-shell (command 'r').

Thursday, January 5, 2012

gnome-shell is not so bad

It seems that I will be able to use GNOME 3. I love the minimalism provided by gnome-shell. It's gnome, so it's tricky to fully customize the desktop, but it's possible.

My requirements:
  • no animations (gnome "switch workspace" is pure hell...)
  • tagging -- at least for terminal (fluxbox supports this for arbitrary application, gnome has at least gnome-terminal with tabs)
  • minimalistic windows decoration
  • no window title for maximized windows
  • tiny window title for normal and modal windows
  • no max/min/close buttons for windows (I have keyboard...)
  • pretty visible focused window (e.g. green border)
  • only one tiny panel
  • WM has to remember workspace for applications (e.g. firefox = 2nd workspace)
We all love screenshots, right? ;-) My old good fluxbox here, and the "same" with GNOME 3 is here.

The first step is to install some gnome-shell extensions:
  • Native Window Placement Extension
  • Auto move windows extension
  • Disable Window Animation Extension
  • Remove User Name Extension
  • windowNavigator Extension
The next steps is to make windows decorations more minimalistic. This step is more tricky, because you have to modify window manager theme (for more details see gnome bug 594879). My theme is available at my home page.

The next step is to customize desktop files for some applications, for example I want to start gnome-terminal with --hide-menubar option, so
cp /usr/share/applications/gnome-terminal.desktop \
~/.local/share/applications/myterm.desktop
and modify Exec and Name entries in the file. Then you can add the application to your gnome-shell Favorites.

The last step is to customize keyboard shortcuts, this is simple (see "keyboard" in gnome-control center).

Note than many things like info about CPU temperature does not have to waste any place on your desktop. IMHO it's better to use keyboard shortcuts and print necessary information to the screen on demand. For example I use osd_cat:
#!/bin/bash

BATT=$(acpitool -b | awk -F ':' '/Battery/ { print $2 }' | sed 's/ //')
AC=$(acpitool -a | awk -F ':' '/AC/ { print $2 }' | sed 's/ //g')
TEMPE=$(sensors | awk '/temp/ { print $2 }' | sed 's/ //g')
FAN=$(sensors | awk '/fan/ { print $2 }' | sed 's/ //g')

(printf " Battery: %-20s\n" "$BATT"
printf " AC: %-20s\n" "$AC"
printf "Temperature: %-20s \n" "$TEMPE"
printf " Fan: %-20s\n" "$FAN") | osd_cat --delay 4 --pos bottom \
--align right --offset 45 --indent 10 \
--color green --font "-misc-fixed-*-*-*-*-20-*-*-*-*-*-*-*"