Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Need to create a SCSI monitoring child process.

by dd-b (Monk)
on May 16, 2013 at 22:44 UTC ( [id://1033922] : note . print w/replies, xml ) Need Help??

in reply to Need to create a SCSI monitoring child process.

Well, you can't do it by directly accessing the main memory from a forked process in Perl; the fork call doc makes that pretty clear.

You need some form of IPC mechanism, so perlipc is a useful place to look. Maybe semaphores, or a shared file, or something.

Replies are listed 'Best First'.
Re^2: Need to create a SCSI monitoring child process.
by LivingDust (Novice) on May 16, 2013 at 23:31 UTC

    The problem with a shared file is I would still need a parallel routine running to check the contents of the shared file. What I want is to write something that checks the status of the SCSI bus every 15 seconds or so and updates some variables, but does not block my main program.

    There are only 10 types of people in this world... those who understand binary, and those who don't.


      what does blocking mean in your context?

      Let's asume the following: You have a child process which scans the scsi bus regularly (e.g. lsscsi) and puts this information into a array of hashes which gets serialized into a file (real file on the file system or shared memory segment). The main program (tk) would try to get a read lock on that file. If it doesn't get it, it continues the event loop (showing the probably old information). If it gets the lock than it reads the information (which should be fast either on a real file or shared memeory (which should be faster)) and diplays it.

      Assumimg communication is done via shared memory, I would expect that the interchange of information between the two processes (gathering information about scsi and reading this information) is done quikly and therefore more or less without blocking.

      Best regards

        Maybe I am missing something. What you suggest works if the main program has a loop that is monitoring this shared memory block (or file). I know there are loops like this that are constantly monitoring the location of the mouse cursor. You can see the display change when the cursor is over a widget. So I know what I want is possible. There are already files on the Linux system that are only present when a drive is inserted. My main program could detect the presence or absence of these files. Or it could do a system query of the SCSI bus (there are lots of system commands to choose from). But what I want is that this subroutine is always running with a sleep timer to recheck for the presence of these files or to re-issue the system command.

        If I don't fork this subroutine, then I never return from the subroutine and my windows never update. But if I fork a process, can my subroutine update global variables in my main process? Is this something I can do in Perl? Or do I need to go to a different language?

        There are only 10 types of people in this world... those who understand binary, and those who don't.