Announcement

Collapse
No announcement yet.

keeping a second occurance of a dos program from running at the same time

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • keeping a second occurance of a dos program from running at the same time

    hello

    in windows i am going to have a problem
    yes i know, i am 7 or so years behind.

    i know this question has probably been covered befor, but i cannot seem to find it.
    i am on win2k and want to keep from running a second occurance of the same program
    at the same time.
    i am going to keep writting in pbdos for now, even though i have pbcc and pb for windows.
    the problem i preceive, coming down the road, is when a preson closes the window box.
    and stops the program before closing out the program in a safe manner.
    i was going to set a flag on then turn it off upon exiting the program.

    i appreciate any experience given, thanks.

    paul


    ------------------


    [This message has been edited by paul d purvis (edited June 08, 2005).]
    p purvis

  • #2
    On Linux I just execute the ps command and search the output for the name of the program. If it's there more than once, the current session is a duplicate.

    ps can tell you who owns the job, so you can allow only one (or two, or three) session for each user but allow multiple users to run the program at the same time as well.

    I suspect that Windows will have a way to list the current tasks too. Find that, and search the list when your program starts.

    ------------------
    PB/DOS 3.5 on Fedora Linux

    Comment


    • #3
      One way is to create a file named something like "NOTBUSY".
      When your program starts rename "NOTBUSY" to "BUSY. If you
      get an error the program is in use. When program terminates
      rename "BUSY" to "NOTBUSY".

      ------------------
      How long is an idea? Write it down.

      Comment


      • #4
        My company's DOSBox product provides "instance control" for DOS programs. For more information and a free download, click on one of the links below.

        -- Eric Pearson, Perfect Sync Software

        ------------------
        Perfect Sync Development Tools
        Perfect Sync Web Site
        Contact Us: mailto:[email protected][email protected]</A>
        "Not my circus, not my monkeys."

        Comment


        • #5
          > One way is to create a file named something like "NOTBUSY".
          > When your program starts rename "NOTBUSY" to "BUSY. If you
          > get an error the program is in use. When program terminates
          > rename "BUSY" to "NOTBUSY".

          Which does you absolutely no good when someone just closes the window that your program is running in, rather than exiting it in the "approved manner".

          ------------------
          PB/DOS 3.5 on Fedora Linux

          Comment


          • #6
            Designate a file.
            When program starts, attempt to OPEN exclusive for I-O. (I'd use SHARED ACCESS READ WRITE LOCK READ WRITE, but you may have to tinker depending on operating system, how it implements command shell, etc)
            If open fails on 70 permission denied, someone else has file open exclusive... the FIRST user. Handle user notification and exit.
            When program ends, CLOSE the file.


            Michael Mattias
            Tal Systems Inc. (retired)
            Racine WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              > I am on win2k

              And since you have Windows compilers ("even though i have pbcc and pb for windows") to go with your Win 2K ....

              Write the 12-line Windows Program which does nothing but attempt to create a mutex (many examples here) and if it can, SHELL "mydosprogram.exe"

              That way you can use 'officially sanctioned synchronization objects" to control the user count.



              [This message has been edited by Michael Mattias (edited June 08, 2005).]
              Michael Mattias
              Tal Systems Inc. (retired)
              Racine WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                > Designate a file. When program starts, attempt to OPEN exclusive for I-O.

                Very clever, Michael! Very clever indeed.

                I shall remember this technique and use it in the future myself.

                Thanks!

                ------------------
                PB/DOS 3.5 on Fedora Linux

                Comment


                • #9
                  thanks for the answers,
                  i am sorry that in my topic i did not specfically mention windows.

                  i really like the ps command suggestion under linux, i will definitly keep the in mind
                  for up coming projects.

                  i am going to try dosbox, but that still is not quiet what i had in mind but i can invision
                  other uses for it.
                  i know that this is not the windows forum and i started to post it there.
                  but i know there are some keen people in this forum and that somebody has solved the question.

                  also what is the formal name given to a program running twice at the same time under windows.

                  thanks
                  paul

                  edited:
                  as i wrote and after i posted the above, is saw the exclusive open file mode.
                  that is good.
                  mutex, i will have to find out what that means but probably it sounds maybe what i am
                  trying to do.
                  i can maybe put a command in a batch file to test for this duplicate stituation then either
                  run the program or skip it.



                  [This message has been edited by paul d purvis (edited June 08, 2005).]
                  p purvis

                  Comment


                  • #10
                    > what is the formal name given to a program running twice at the same time under windows.

                    Each time a program is run it creates an "instance" of the program. I'm not aware of any official name for a program that is run twice, other than "two instances".

                    -- Eric

                    ------------------
                    Perfect Sync Development Tools
                    Perfect Sync Web Site
                    Contact Us: mailto:[email protected][email protected]ectsync.com</A>
                    "Not my circus, not my monkeys."

                    Comment


                    • #11
                      ok here is my sick idea and i do not know it will even work but i do try hard.

                      my msdos file server is not using file locking for multiple reasons but most
                      of my data files and program files from msdos are on it.

                      1. practice the suggestion of locking a file on the local windows computer.
                      i will call this the tagged file.

                      2. start a tsr program from a batch file to open the tagged file as locked on the local computer

                      3. test the tagged file inside the tsr program before exiting the tsr and send somekind of exitcode or lack of exitcode to msdos.

                      4. in the batch file test the exitcode or lack of an exitcode

                      5. make a desicion in the batch file whether to execute the program we want running only once
                      or end the batch file without running the program we only want to run one instance of.

                      6. if the batch file decides to execute the program, after the program closes,
                      the tsr must close or erase the file and terminate itself.


                      big question?
                      if i remember correctly you can exit a pb program and leave a dos exitcode.
                      but i have never did that before.

                      i could use some help here in doing exit codes.


                      i am going to write the tsr and posted it back on another thread to get some feedback.

                      once again here, the tsr's job will be to keep a file open in locked mode on a local computer.
                      i will try to put the file's name on the command line so that it can be placed anywhere.

                      one other question will be, what is going on to the file when somebody closes the window,


                      i hope the program is better than my english.

                      thanks
                      paul


                      [This message has been edited by paul d purvis (edited June 08, 2005).]
                      p purvis

                      Comment


                      • #12
                        OK
                        got the error code for the EXIT statement figured out for the batch file.

                        paul


                        ------------------
                        p purvis

                        Comment


                        • #13
                          You're doing it the hard way. Why not just put the file open command ( and file close) into the program that you're trying to execute/check, instead of doing it externally?

                          The command you're looking for is end(DOS error code), by the way.

                          Here is the information from MS about how to use their tasklist command:
                          http://www.microsoft.com/resources/d.../tasklist.mspx

                          ------------------
                          PB/DOS 3.5 on Fedora Linux

                          Comment


                          • #14
                            i could do it in my own program
                            it is a third party program for msdos i want to run under windows.
                            thanks for the note on tasklist
                            i want something more generic.
                            i do not like doing things the hard way but it seems i am always get the hard stuff to do
                            things that other people say cannot be done or walk away from.

                            thanks a million on the reply, honestly
                            paul



                            ------------------
                            p purvis

                            Comment


                            • #15
                              ok
                              i am having trouble with keeping a file open inside a tsr after i popdown(popup sleep).
                              so can i open a file in a tsr then leave the file open then poping down
                              with the tsr resident.
                              paul


                              ------------------
                              p purvis

                              Comment


                              • #16
                                on another thread i found

                                Rod Mack
                                unregistered posted May 17, 1999 01:49 PM We have an application where we need to keep
                                the com port RTS signal line on between
                                TSR invocations for powering of external
                                device.

                                Normal operation of the TSR requires CLOSING
                                the COM port when the TSR is terminated -
                                thus terminating the RTS signal. Glitches on the
                                RTS line are undesirable.

                                Thanks

                                Rod Mack

                                Dave Navarro
                                Member posted May 17, 1999 04:43 PM Click Here to See the Profile for Dave Navarro You need to write another TSR in assembler or C to handle the communications side of things for you (buffer incoming data) and use CALL INTERRUPT in your PowerBASIC TSR to communicate with the other driver.

                                It simply isn't possible to keep files or COM ports open in a PowerBASIC TSR.

                                --Dave

                                ------------------
                                p purvis

                                Comment

                                Working...
                                X