Randal Schwartz wrote an example link checker which used forked processes to run tasks in parallel. Each child process created has a read pipe from and a write pipe to the parent (created with
The result is an inverted version of my preferred architecture. I like the parent to dump work on a queue and whichever child is ready to pull it off. This is pretty easy to do with threads.
In Randal’s version, the parent figures out which child is available to do work.
Posted in Perl | Tagged fork, multi-processing | 2 Comments »
My grub menu finally got scrollbars so I decided to look into how to remove old linux kernels.
The easiest instructions I found are here.
I checked which kernels are installed in
$ ls /boot/vmlinuz*
And then removed everything apart from current and one version back.
sudo apt-get remove - --purge 2.6.32-28-*
Posted in Miscellaneous | Tagged linux, useful | Leave a Comment »
My question about how windows works without fork got pointers to two useful Windows perl modules in the comments:
Spawning External Programs
(from dagolden) See Win32::Job or just use
system(1, $cmd, @args)
(from Christian Walde) Use Win32::Detached
What I was really wondering about was how reliable software was written without fork. What do I mean by that?
What is the difference between?
If the child thread misbehaves – exits, dumps core, leaks memory, or whatever, that’s bad for the parent. Child processes can’t wreak quite so much havoc.
Presumably the solution adopted in Window is don’t do stuff in threads that causes them to accidentally exit [the whole process], dump core or leak memory.
Posted in Perl | Tagged processes, windows | 7 Comments »
How does windows work without fork? So many things start with a call to fork: starting a new process (fork/exec), creating a daemon, creating independent tasks within one program…
The nice thing about all of these things is, if a new process goes bad, it probably won’t take out the parent process. You don’t get the same safety with a thread. Therefore, fork is the basis of a lot of my reliable software.
I’m fairly confident that windows doesn’t have anything similar to fork. Otherwise the perl fork emulation could simply wrap whatever windows has. Sadly it doesn’t quite work that nicely.
While the emulation is designed to be as compatible as possible with the real fork() at the level of the Perl program, there are certain important differences that stem from the fact that all the pseudo child "processes" created this way live in the same real process as far as the operating system is concerned.
If the parent process is killed (either using Perl’s kill() builtin, or using some external means) all the pseudo-processes are killed as well, and the whole process exits.
I have been approaching this problem of reliable windows software from too low a level. Rather than copying what I do on Unix and start with fork (using Perl more or less as my OS wrapper), I now use web servers to manage my processes.
Posted in Programming | Tagged fork, reliability, reliable software | 4 Comments »
Previously, I’ve talked about integrating little perl "services" into emacs that read from stdin and write to stdout.
Sometimes the processes that make up your emacs application are running on different servers, picking up various pieces of information and it might be necessary to kill them independently or in groups. By default, comint binds C-c C-c to SIGINT, but if you have a moderately complex application, you don’t want to go through each comint buffer and kill the processes individually.
Each of your perl scripts needs to output the PID and the server it is running on.
my $hostname = hostname();
print "Started PID $$ on $hostname\n";
Then the emacs application code needs to use a filter to read that information into a couple of variables.
(defvar proc-pid nil)
(defvar proc-host nil)
"Started PID \\([0-9]+\\) on \\([a-z0-9]+\\)")
(defun proc-filter (output)
(when (string-match *re-match-pid-host* output)
(setq proc-pid (match-string 1 output))
(setq proc-host (match-string 2 output)))
(add-hook 'comint-preoutput-filter-functions 'proc-filter)
Running commands remotely is easy with ssh. (Incidentally, how does this work in windows-land?)
(defconst *ssh* "ssh -o StrictHostKeyChecking=no")
(defun kill-proc ()
(let ((cmd (format "%s %s kill %s" *ssh* proc-host proc-pid)))
(message (shell-command-to-string cmd))))
I’ve demonstrated the
make-comint code previously.
(defun start-proc ()
(let ((buffer (get-buffer "*stdin-proc*")))
(when buffer (kill-buffer "*stdin-proc*")))
(apply 'make-comint "stdin-proc" "perl" nil
And the result is as expected.
Started PID 5008 on saturn
Process stdin-proc terminated
Posted in Emacs | Tagged emacs comint | Leave a Comment »
It’s hard to objectively measure Perl’s popularity compared to Python or Ruby. Even before nerds-central used job availability as a measurement, the ease of finding a job was a key requirement for me.
Who cares if I love Ruby if I can’t use it for the 10 hours a day I’m working?
In the last twelve years I’ve had no difficulty finding plenty of Perl work. In the past couple of years, I’ve had a few calls about Python jobs, but probably ten times fewer than the number of Perl calls I get. Hold the front page – Perl is ten times more popular than Python.
Well, no. Of course I get a lot more Perl calls. I’m a Perl programmer, and my résumé mentions Perl all over the place. Anyone calling about Python must really be desperate!
But I notice that a lot of Python programmers working at Python-centric firms apply similar logic. All the folks they work with do Python, clearly no-one does Perl anymore. Thank goodness – Python is finally the winner it always deserved to be.
Why do people care?
Network effects are important. All other things being equal, a language with more users will get more libraries, will have more companies using it, will get more users, will get more libraries, etc. vs a language with fewer users. And, popularity aside, none of the big three scripting languages has a huge advantage over the others.
Except of course that Perl was the first mover.
So, what can you do if you don’t have a real advantage you can point to? That’s right – you trash-talk the leader, hope you can convince enough people there is a real problem and when they jump ship hopefully you’ll be the one left with the positive feedback loop.
Posted in Perl | 2 Comments »
Michael Murdock doesn’t believe in anti-Perlism. Of course he has to indulge in some of his own.
“Every developer with whom I have discussed this issue says roughly the same thing: It’s very difficult to pick up a piece of Perl code, even when it’s your own, and be able to quickly understand the gist of it.”
I find it hard to understand French but I don’t go round saying it is a speak-only language.
You couldn’t make it up. Or was the irony intentional?
Posted in Perl | 11 Comments »