Are file descriptors shared when fork()ing?

From fork(2): * The child inherits copies of the parent’s set of open file descrip- tors. Each file descriptor in the child refers to the same open file description (see open(2)) as the corresponding file descriptor in the parent. This means that the two descriptors share open file status flags, current file offset, and signal-driven … Read more

SIGKILL signal Handler

You cannot, at least not for the process being killed. What you can do is arrange for the parent process to watch for the child process’s death, and act accordingly. Any decent process supervision system, such as daemontools, has such a facility built in.

UDP-Broadcast on all interfaces

First of all, you should consider broadcast obsolete, specially INADDR_BROADCAST (255.255.255.255). Your question highlights exactly one of the reasons that broadcast is unsuitable. It should die along with IPv4 (hopefully). Note that IPv6 doesn’t even have a concept of broadcast (multicast is used, instead). INADDR_BROADCAST is limited to the local link. Nowadays, it’s only visible … Read more

Java Time Zone is messed up

It’s a “quirk” in the way the JVM looks up the zoneinfo file. See Bug ID 6456628. The easiest workaround is to make /etc/localtime a symlink to the correct zoneinfo file. For Pacific time, the following commands should work: # sudo cp /etc/localtime /etc/localtime.dist # sudo ln -fs /usr/share/zoneinfo/America/Los_Angeles /etc/localtime I haven’t had any problems … Read more

sed join lines together

sed ‘:a;/0$/{N;s/\n//;ba}’ In a loop (branch ba to label :a), if the current line ends in 0 (/0$/) append next line (N) and remove inner newline (s/\n//). awk: awk ‘{while(/0$/) { getline a; $0=$0 a; sub(/\n/,_) }; print}’ Perl: perl -pe ‘$_.=<>,s/\n// while /0$/’ bash: while read line; do if [ ${line: -1:1} != “0” … Read more