0

I'm working with system V shared memory in an application. during development I need to inspect and, sometimes, delete the memory segment. I know there is the ipcs command to inspect shared memory, and there is ipcrm to delete. My only problem is, I first need to look up the shmid of the shared memory segment using ipcs -m, identify the correct one, and then delete it using ipcrm -m <shmih>. In my application I'm using ftok() to identify the shared memory segment using a file and an identifier, which is much easier (one can use ipcrm -M to delete a shared memory segment using its key instead of shmid). Is there an ftok command for the shell? By default, my ubuntu server has none, and inpecting man files I didn't find any hint on one either.
A shell script or binary that creates the same IDs as ftok does is fine, too... I just don't want to use any other intperpreter than /bin/sh or /bin/bash for compatibility reasons. ANd I don't know too much C, so unfortunately I cannot just write my own.

1 Answer 1

0

I believe there is. I have never used it, but I kept the following reference for use, should need arise: here. The title of the post,

ftok in bash

is self-explanatory. Hope this helps.

3
  • Thanks for the link! unfortunately, the code there doesn'T really work. The outpuit doesn't fit the keys a system ftok() call creates. It's not completely wrong however, just slightly different... ipcs -m states, that the key for the shared memory I have is 0x6e4f0360, while that ftok-implementation gives me 4f0360n. But I have never seen a system V key with a letter in it... so maybe that was working for older/other versions of system v, but doesn't fit mine. Feb 9, 2014 at 23:50
  • Looking closer at that code, it's obvious that that can't work, at least not on GNU Linux. The "n" in fprints first argument is just output as-is, that's why I get the n there... and the generated hex number is too short to ever get 6e4f0360. WHen googling, I discovered some C source code that used the same generation, apparently from an apple binary. SO maye they're dogin things a little different. (the n in fprint may also work on apple's fprint, don't know) Feb 10, 2014 at 0:05
  • Erm, nope, nevermind. Linux source is the same. Feb 10, 2014 at 0:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .