Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSystemSemaphore location on linux

QSystemSemaphore location on linux

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alexsho
    wrote on last edited by
    #1

    I'm developing two applications on linux that have to be synchronized.
    One application is regular C++ and a second is Qt.
    The C++ application opens Posix named semaphore as sem_open(...), and the Qt opens QSystemSemaphore.
    Tere is no strict order in opening the apps. Each one configured to connect to the existing semaphore in case it started as a second.
    The C++ semaphore i can see at /dev/shm, but the Qt semaphore i can't found.
    Where is it stored ?
    If it's system resource, why it is not stored in standard place ?

    1 Reply Last reply
    0
    • kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @alexsho
      Hello,
      If both applications are going to be synchronized through the same semaphore, then you have to pass the same name both for the the Qt app and your C++ program. Doing that will open only one semaphore, so why would you expect to see two separate primitives?

      Kind regards.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alexsho
        wrote on last edited by alexsho
        #3

        I do define the same name. I know that QT adds prefix and SHA hash to the name.
        The problem that the applications still don't open same semaphore.
        When i tested the applications as stand alone, to check where it creates (or looks for ) the semaphore, the C++ app creates its semaphore at the defined place: /dev/shm/, but the Qt app don't , or it is created in some another place.
        As i understand, if i want the apps to open the same semaphore - it should be pointed to the same place.
        When Qt app runs alone, the QSystemSemaphore object is creared without errors, but i can't found it in the system.

        kshegunovK 1 Reply Last reply
        0
        • A alexsho

          I do define the same name. I know that QT adds prefix and SHA hash to the name.
          The problem that the applications still don't open same semaphore.
          When i tested the applications as stand alone, to check where it creates (or looks for ) the semaphore, the C++ app creates its semaphore at the defined place: /dev/shm/, but the Qt app don't , or it is created in some another place.
          As i understand, if i want the apps to open the same semaphore - it should be pointed to the same place.
          When Qt app runs alone, the QSystemSemaphore object is creared without errors, but i can't found it in the system.

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by kshegunov
          #4

          @alexsho

          Suppose you've given key to Qt for the semaphore, then the file path is:

          QDir::tempPath() + "/qipc_systemsem_" + keyStripped + QCryptographicHash::hash(key.toUtf8(), QCryptographicHash::Sha1).toHex()
          

          Where keyStripped is the key variable but every character that is not in the range a-z, A-Z is removed.

          Does that help?

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          0
          • A Offline
            A Offline
            alexsho
            wrote on last edited by
            #5

            I know that, this is the way the semaphore name is build on Qt.
            I did the same on the C++ app, using external SHA1 function, and i get the same name.
            The problem is that the default location of the Qt semaphore is probably differ from default system location.
            I believe that two Qt applications will found each other, but in my case one app is general C++.
            I solved the similar problem with QSharedMemory, but
            in QSharedMemory there is a possibility to set NativeKey, then this will be the exact name of the created object. What i did is - i added the path prefix /dev/shm/ to the name and set it as Native.
            That way i forced Qt to create (or found) the shared object in system standard place where the C++ app creates it.
            In QSystemSemaphore there is no possibility to set Native Key, the Qt always adds its prefix, so i can't control the location of the object (i hope i'm wrong).
            I must then try to change the location of the C++ semaphore.

            kshegunovK 1 Reply Last reply
            0
            • A alexsho

              I know that, this is the way the semaphore name is build on Qt.
              I did the same on the C++ app, using external SHA1 function, and i get the same name.
              The problem is that the default location of the Qt semaphore is probably differ from default system location.
              I believe that two Qt applications will found each other, but in my case one app is general C++.
              I solved the similar problem with QSharedMemory, but
              in QSharedMemory there is a possibility to set NativeKey, then this will be the exact name of the created object. What i did is - i added the path prefix /dev/shm/ to the name and set it as Native.
              That way i forced Qt to create (or found) the shared object in system standard place where the C++ app creates it.
              In QSystemSemaphore there is no possibility to set Native Key, the Qt always adds its prefix, so i can't control the location of the object (i hope i'm wrong).
              I must then try to change the location of the C++ semaphore.

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by kshegunov
              #6

              @alexsho

              The problem is that the default location of the Qt semaphore is probably differ from default system location.

              The location Qt uses is QDir::tempPath() as written in my previous post.

              That way i forced Qt to create (or found) the shared object in system standard place where the C++ app creates it.
              In QSystemSemaphore there is no possibility to set Native Key, the Qt always adds its prefix, so i can't control the location of the object (i hope i'm wrong).

              Not to my knowledge.

              Kind regards.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              0
              • A Offline
                A Offline
                alexsho
                wrote on last edited by
                #7

                Sorry i missed that.
                That is the point.
                Thank you.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved