Why fork(2) doesn’t copy all threads?

There are many advises discouraging the use of fork in threaded applications…it is even on “Programming with POSIX Threads” by Butenhof….Avoid using fork in threaded program (if you can) unless you intend to exec a new program immediately.

Certainly using fork in threaded programs is not a good idea but sometimes it becomes necessary, so, the point is: why fork(2) doesn’t copy all threads?

First time I  asked myself  “does a forked process have all the parent’s threads?” I thought yes but, I was wrong.  The specification say it: A process shall be created with a single thread

So why?

  • Because is more practical, easier, and less complex.
    • There are only two alternatives, copy all of them or copy just the one calling fork. Each alternative has it own set of complexities, so, which approach is easier to follow? Copying only the thread that called fork.
  • Critical sections: Other threads could be executing critical sections at fork() call, therefore child process might get a copy of objects that are in undefined status => causing undefined behavior on the application. Σ =
  • Parent and child could be reading from fd or socket at the same time, or even worse writing to it.  あぶない
  • Since state in parent and child should be the same, all parent’s threads should be stopped before to be forked and if in the middle of a system call EINTR would be raised
  • .

Specification mentions forkall was rejected, that means that I was not alone.
It is easier to deal with one thread using pthread_atfork() than dealing with multiple threads on the child.
As long as it is specified it is OK

WGET Error `http://:8080/’: Invalid host name SOLVED

Some days a go i tried to use wget to download some files from internet, and I alway got the error `http://:8080/': Invalid host name, I read the man page but I couldn’t find anything that help me to solve the problem, then I searched in internet but anything again. So I used Opera to download the files, but I was not quite trying to know the strange behavior of wget but I leaf it in peace.

And now while I was testing a c program which uses extern char **environ I saw environ[10]: http_proxy=http://:8080/, I thought I had the answer to the strange behavior of wget, and I was right.

To solve it do
$ unset http_proxy

And in gnome look at System->preferences->Internet->proxy

Gnome proxy
Be sure to your proxy is well configured or choose direct connection

Receta de cocina: cliente DHCP en OpenSolaris y/o Solaris 10

Se asume que:

– iwi0 es la interfaz primaria.

– El nombre del nodo es vaio

1. $ sudo hostname -S vaio

2. $ sudo vi /etc/nodename

: edita este archivo de forma que sólo contenga vaio

$ cat /etc/nodename


3. $ sudo touch /etc/hostame.iwi0
4. $ sudo touch /etc/dhcp.iwi0

5 . $ sudo vi /etc/nsswitch.conf

:edita la linea que continene files, añade dns; quedaría: files dns

6. $ sudo touch /etc/resolv.conf

7. Reiniciar la maquina, o reiniciar servicios de red, o ifconfig iwi0 dhcp, o wificonfig -i iwi0 auto

8. (Opcional) Revisar que /etc/default/dhcpagent tenga RELEASE_ON_SIGTERM=yes. Aunque es preferible configurar estas cuestiones del lado del servidor.