Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 890887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:48:17+00:00 2026-05-15T13:48:17+00:00

It is mentioned in ftok() manual key_t ftok(const char *pathname, int proj_id); The ftok()

  • 0

It is mentioned in ftok() manual

key_t ftok(const char *pathname, int proj_id);

The ftok() function uses the identity of the file named by the given pathname (which must refer to an existing, accessible file) …

I am confused about const char *pathname.

What would be the best practice for it?
On my current system I can pass "/home/Andrew/anyfile" but it is not possible that other systems, on which my program has to work, will have this file.

How about I use "/etc/hosts/" or "/etc/inittab" because I am sure all such systems will have these two files? Is it a good idea? Can it cause any problem?

I do not want to ask user to enter filename at the time of execution or pass file name as command line argument.

Is there any other different and better way to decide pathname?
Which way is the best and most reliable one?

Thanks for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:48:18+00:00Added an answer on May 15, 2026 at 1:48 pm

    Well, generally you would use a file associated with the application itself.

    For example, we had an application which loaded a configuration file into shared memory (in a parsed efficiently accessible way – think of an XML file which has been turned into in-memory structures with fast pointers and so forth) and we created the shared memory segment from the ftok derived from the configuration file itself.

    Worst case, if you have no configuration files for your application, try to use the executable itself. You can be pretty certain that it exists on the system somewhere (since you’re running it).

    You’re also not restricted to files, you can use /etc itself or /tmp or even / if you must.

    I say “if you must” because it’s a little bit dangerous. The ftok call will give you a unique key based on your file spec and your ID. If you use your own file such as /etc/andrew.conf, you can be reasonably certain that you won’t get a clash with any other ftok-returned key.

    However, if you, and everyone else, decides to use /tmp as the file spec part then the only differentiator is the ID. Hence it’s a lot easier to get a collision with other keys.

    What I’ve always done is to use the file spec as a truly unique value for my application and then just use the ID for the particular thing I want to create.

    So, if I need 27 semaphores and 15 shared memory blocks, they all use /etc/pax.conf as the file spec and the IDs from 1 to 42 (and my application knows what ID relates to what object).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

somebody mentioned that the function (in this case a method) below is no good
I get the error mentioned here: C++ Templates Error: no matching function for call
as mentioned in title. Another details: file is in on my hard drive in
As mentioned in the Zend Framework manual , I created a base controller. Subclassing
below mentioned is my c++/cli *.h file // rmsCInterfaceWrapper.h #ifndef RMSCINTERFACE_H #define RMSCINTERFACE_H #ifndef
I get the below mentioned while restoring a database back-up file to my system.
As mentioned i would like to know how i can apply the live() function
As mentioned in the docs the optparse.OptionParser uses an IndentedHelpFormatter to output the formatted
as mentioned in some other threads i'm a having trouble to setText inside a
As mentioned in the title, my launcher icon is showing up fine on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.