Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

dirent

Posted on 2001-08-02
13
Medium Priority
?
204 Views
Last Modified: 2010-04-02
Hi

Can anyone explain me how to read the process ID from the  Unix struct dirent (found in man dirent).

Thank,

Liron
0
Comment
Question by:lirong
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 4

Expert Comment

by:IainHere
ID: 6344039
Do you want the PID of the calling proces?  If so, use the getsid() function (also in man pages).  I can't see how you'd get it from dirent - you could find everything in /proc, but why would that be useful?
0
 
LVL 2

Expert Comment

by:sateesh_babu
ID: 6344122
I have go thru the man page for dirent, and I find that there is no entry to get the process id. dirent is a structure that holds directory entries, and not related to processes. What does your question actually relate to?
Babu
0
 

Author Comment

by:lirong
ID: 6344209
Know. I'm want to know (from a C app)a process ID.

Do you have another way to do so ?

Liron
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:IainHere
ID: 6344218
Yes. getpid() will give you the current process's ID (rather than getsid(), sorry).  getppid() will get the parent's ID.
0
 

Author Comment

by:lirong
ID: 6344232
But I don't want to know my PID I wish to know another process PID. for example I'm running process X and with to know process Y pid.
0
 
LVL 4

Expert Comment

by:IainHere
ID: 6344244
If you're trying to get the PID of a different process, there is no standard way of doing it.  Since you can have more than one process with a particular name, there can be no function that will return a PID when given an application's name.

You could (if your flavour of unix provides one) trawl through the /proc directory, which contains all of the PIDs as filenames, open each and query them.  This is generally not a good solution, since you should restrict /proc to superuser only (imagine rm -r /proc, which a colleague of mine did on a DEC Alphaserver, which at the time was the interface to a power station's control system)
0
 
LVL 4

Expert Comment

by:IainHere
ID: 6344250
from http://www.npl.washington.edu/faq/unix-FAQ-3-10.html


      However, some vendors provide functions for reading Kernel
      memory; for example, Sun provides the "kvm_" functions, and Data
      General provides the "dg_" functions.  It may be possible for any
      user to use these, or they may only be useable by the super-user
      (or a user in group "kmem") if read-access to kernel memory on
      your system is restricted.  Furthermore, these functions are
      often not documented or documented badly, and might change from
      release to release.

0
 

Author Comment

by:lirong
ID: 6344260
I know that I can see the process list from /proc. That is why I want to use opendir function and dirent structure. Do you know how can I know what is the process ID using dirent structure ?
0
 
LVL 4

Accepted Solution

by:
IainHere earned 600 total points
ID: 6344269
Are you creating process Y with fork()?  If so, the return value will be the PID.

The PID is the name of the file.  That is stored in dirent::d_name.
0
 
LVL 4

Expert Comment

by:IainHere
ID: 6344285
Go to this page
http://docs.linux.cz/c-faq_comp.unix.programmer/faq.txt

and find the text "Reading the process table using popen and ps"

There are examples of how to do it the way you are describing, but popen is better.  Will this solve your problem?
0
 
LVL 4

Expert Comment

by:IainHere
ID: 6362908
lirong,

Did you solve your problem?  If not, you should continue to ask here for help.  If you did, and any of the above was of use, please accept one of the comments as an answer.  If none of the comments were useful, you can delete the question.

Thanks.
0
 
LVL 11

Expert Comment

by:griessh
ID: 6842554
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to accept "IanHere" comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points.
The link to the Community Support area is: http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

lirong
You have several open questions that need your attention. Please take some time, look into your profile/Question History and either close some of these or give some feedback to the experts.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 

Expert Comment

by:ComTech
ID: 6858037
After review, the proposed answer will be accepted by:

ComTech
Community Support Admin
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question