Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Locking von Files

Empfohlene Antworten

Veröffentlicht

Hallo!

Angenommen ich habe zwei Programme, die beide auf eine Datei zugreifen können (lesen und schreiben).

In PHP ist es möglich eine Datei zu locken (wenn ich sie geöffnet habe), so dass ein anderes Programm sehen kann, dass diese Datei gelockt ist und so lange warten kann, bis die Datei wieder geunlockt wird.

Gibt es das auch in C?

Wenn ja, würd mich mich sehr über Vorschläge freuen.

Ich möchte einfach nicht, dass das eine Programm schon liest, während das andere noch schreibt. Sozusagen ein Mutex ^_^

Danke schonmal

Anmerkung: Ich arbeite natürlich unter Linux

ich habe doch 2 programme, die nichts miteinander zu tun haben.

mutexe kenn ich nur in verwendung mit posix threads.

diese art der anwendung nützt mir bei diesem problem leider garnichts.

woher soll das eine programm wissen dass das andere gerade den mutex hat?

für das Betriebssystem Linux-2.6.13 bitte =)

das wär echt stark =)

danke dir :-)

Hallo!

Angenommen ich habe zwei Programme, die beide auf eine Datei zugreifen können (lesen und schreiben).

Gibt es das auch in C?

Im Standard nicht aber so könnte es z.B. aussehen (bsp von hackin9):


#include <stdio.h>

#include <unistd.h>

#include <fcntl.h>


int main()

{

  FILE *fp;

  int c;

  struct flock fl;


  fl.l_type = F_WRLCK;      /* Write locking on */

  fl.l_whence = SEEK_SET;

  fl.l_start = 0;

  fl.l_len = 0;


  fp = fopen("sequence", "r+");


  /* Waiting for a lock */

  fcntl(fileno(fp), F_SETLKW, &fl);


  fscanf(fp, "%d", &c);


  c++;

  printf("My no.: %d\n", c);

  usleep(1);

  /* Writing the new number to a file */

  rewind(fp);

  fprintf(fp, "%d\n", c);


  fl.l_type = F_UNLCK;      /* Locking off */

  fcntl(fileno(fp), F_SETLK, &fl);


  .........

}

http://www.opengroup.org/onlinepubs/009695399/basedefs/fcntl.h.html

:)

herzlichen dank an die moo-kuh und nic_power :)

jetzt sollte ich es schaffen :marine

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.