Showing posts with label FreeBSD. Show all posts
Showing posts with label FreeBSD. Show all posts

Sunday, December 7, 2008

Long "which" command form

To display not only where is location of which argument,
but also attributes, and if it is symlink, on what binary this symlink points.

example of usage:


rtg@kubic-roman:~$ lwhich mine
error:no such
rtg@kubic-roman:~$ lwhich which
lrwxrwxrwx 1 root root 10 2008-05-01 01:30 /usr/bin/which -> /bin/which
rtg@kubic-roman:~$ lwhich nawk
lrwxrwxrwx 1 root root 22 2007-10-20 04:33 /usr/bin/nawk -> /etc/alternatives/nawk
rtg@kubic-roman:~$ ls -la /etc/alternatives/nawk
lrwxrwxrwx 1 root root 13 2008-05-01 16:49 /etc/alternatives/nawk -> /usr/bin/gawk


To use:
add in your .bashrc :


function lwhich
{
awhich=`which $1`
if [ "a$awhich" != "a" ] # or just if [ $awhich ]
then
ls -l $awhich
else
echo "error:no such"
fi
}


(re)start bash shell.

Freebsd 7.0 install on home box failed :(



Found PS/2 keyboard to install Freebsd 7.0 on home AMD64 box.
Got just a reboot after 15 seconds.

Seems FreeBSD still doesn't like my hardware :(

Got funny messages about Giant Lock's and [panic] ohci_add_done.



Rebooted in CentOs.

Tuesday, December 2, 2008

Different signal handling under FreeBSD and Linux

Signals Delivery and SA_RESTART:

Under 2.6 i386 Linux at home I have got all of this signals.

Under amd64 FreeBSD I have got only some of them.

That way under FreeBSD there are no warranty on signals delivery.


#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <semaphore.h>

const int MAX_CHI=1000;

volatile int chld_count;

sem_t asem;

void handler(int sig)
{
pid_t pid;
sem_wait(&asem);
chld_count ++;
pid = wait(NULL);

printf("Pid %d exited. count: %d\n", pid, chld_count);
sem_post(&asem);
}

int main(void)
{
int i;
chld_count=0;
struct sigaction sa;
sem_init(&asem,0,1);

signal(SIGCHLD, handler);

sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
sa.sa_handler = handler;

sigaction(SIGCHLD, &sa, NULL);

for(i=0;i<MAX_CHI;i++)
{
int ret_val;
ret_val=fork();

if(ret_val==-1)
{
perror("fork()");
}
else if(!ret_val)
{
printf("in child;Child pid is %d\n", getpid());
exit(0);
}
else
{
printf("Parent pid is %d; child is %d;\n",
getpid(),ret_val);
}
}

for(i=0;i<MAX_CHI;i++)
{
int wparam;
wait(&wparam);
}

return 0;
}

Wednesday, November 26, 2008

bookmarks on books been read in different time and steel having value:

http://samizdat.mines.edu/howto/HowToBeAProgrammer.html?p=1#id2854043: How to be a programmer. good and short.

http://www.yendor.com/programming/unix/apue/apue.html - classical book by Stevens. Very good one.

http://www.advancedlinuxprogramming.com/ not such a good as AUP book by Stevens, but worth to see.

http://www.cs.fsu.edu/~xyuan/cop5570/ - another advanced source, .ppt with examples.

http://catb.org/~esr/writings/taoup/html/ Art of unix programming - very good for understanding architectural principles of Unixes.

http://www.khmere.com/freebsd_book/index.html

HOT:
http://www.tldp.org/HOWTO/Linux+FreeBSD.html

Tuesday, November 25, 2008

Signal delivery failed under FreeBSD.

Some unexpected staff from system well known for stability:
http://www.freebsd.org/cgi/query-pr.cgi?pr=129172

Strange, thу code cited under the link works fine under (Ubuntu 8.04) GNU/Linux.

Monday, November 24, 2008

freebsd biord in top

It is state, like deadlock, when kernel is waiting for disk.
wdrain is like this.

These both are undocumented states of kernel.

If you catched biord or wdrain (or ffsfsn, or some other strange status (that is not kserel, CPU, select or other statuses normally displayed in top), most probably you have serious problems with i/o of your application.

Last 3 monthes events

FreeBSD 6.3 installed and configured (and reconfigured a lot of times).
Very different from stable production one's.

ipfw, pf, and semaphores are in separate kernel modules that is strange.
Very different administration utilities from Linux.

However, it is much more friendly to developer than AIX (if do not consider commercial tools).

Mysql actively used. Moved completely to open-source tools.

Moved to group work ( from stand-slone mode ).