Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Other Discussions
  3. IT & Infrastructure
  4. How to create a semaphore for a file

How to create a semaphore for a file

Scheduled Pinned Locked Moved IT & Infrastructure
helptutorial
1 Posts 1 Posters 0 Views 1 Watching
  • 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.
  • G Offline
    G Offline
    gmlnd
    wrote on last edited by
    #1

    I have created a file and I'm trying to create a semaphore for it using POSIX system calls. My program creates children processes who will open the file and write their pid in the file at the same time. This is my file: void Parent process() File *p, *p2; p=fopen("file1", "w+"); if(p==NULL) //error else fprintf(p,"%u", getpid()) pclose(p); p2=fopen("file2", "w+"); if(p2==NULL) //error else fprintf(p2,"%u", getpid()) pclose(p2); void child1(){ pid=fork(); if (pid==0) //open file1 and write its pid there //open file2 //close file2 //close file1 } void child1(){ pid=fork(); if (pid==0) //open file2 and write its pid there //open file1 //close file1 //close file2 }

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups