Find the answer to your Linux question:
Results 1 to 2 of 2
Hi, I have a doubt regarding mutex usage.Can mutex be used for process synchronization?What i know is mutex can be used for thread synchronization.For process synchronization semaphores are used....
  1. #1
    Just Joined!
    Join Date
    Dec 2011
    Posts
    5

    Mutex for process synchronization

    Hi,
    I have a doubt regarding mutex usage.Can mutex be used for process synchronization?What i know is mutex can be used for thread synchronization.For process synchronization semaphores are used.

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    A semaphore and a mutex are essentially the same thing: a mutex is a semaphore with n = 1.

    You cannot use mutexes and semaphores across processes because they live in a single process's memory space (though shared memory may be able to get around this). A common cross-process locking mechanism is to use kernel-enforced filesystem locks on lockfiles. For instance:

    1) Process A gains exclusive lock on file "./lockfile"
    2) Process A begins processing.
    3) Process B attempts to gain exclusive lock on file "./lockfile" and blocks.
    4) Process A finishes and releases lock on file "./lockfile"
    5) Process B gains lock on file "./lockfile" and then does its processing.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...