Category Archives: Tech Stuff

Cleanup of shared memory segments used by multiple processes

One way to synchronize multiple processes is to use shared memory segments:

/* get id of shared memory segment with key shmkey - if not existing, create one */
int shmid = shmget(shmkey, size, IPC_CREAT | S_IRUSR | S_IWUSR);
/* attach the shared memory segment */
void *mem = shmat(shmid, 0, 0);
/* do some read/write stuff on shared memory */
/* detach shared memory segment */
/* 'remove' shared memory segment */
shmctl(shmid, IPC_RMID, NULL);

The last step will not remove the shared memory segment immediately. It will mark the shared memory segment as to be deleted. If all processes are detached, the shared memory segment is deleted.

So the question is, can we can use that behaviour as is for an automatic cleanup of a shared memory segment, if we think of multiple in parallel running processes with different starting times.
Continue reading Cleanup of shared memory segments used by multiple processes

VI: search and replace in multiple files

If you have opened multiple files, you can search and replace a text in all files by doing:

:argdo %s/search/replace/gec | update

This will replace all occurences of ‘search’ by ‘replace’, asking you for confirmation before doing each replacement. The e in /gec is used to supress error messages in case that the search string was not found in a file

(reference: (12/04/2013) James O’Beirne: Search and replace across many files in vim)