To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 1553
1552  |  1554
Subject: 
Re: getpid?
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Thu, 14 Dec 2000 14:59:02 GMT
Viewed: 
1341 times
  
I am looking for a way how to obtain an identifier of a calling
thread/process...

the launching process does get its PID as a return value from
execi(), you could pass in a pointer to some storage in the
argv, and then update that storage...
Just out of curiosity, why do you need this?

this is not exactly what I meant. What I am looking for is how
can a piece of code determine which process is currently executing
it. something like:

  main(...)
   ...
   create 2 processes with pid1, pid2
   ...

  these processes occasionally call function f():

  f(...)
   ....
   if (getpid() == pid1)
     // process 1 goes this way...
   else if (getpid() == pid2)
     // process 2 does something else here...
   ...

Using this principle I wanted to avoid calling the same
function again by the same process while still allowing
other processes to enter (keeping an array of flags whether
the process already entered the function for all processes)
- since the function can be in principle indirectly
recursive, but should not be called recursively...

the implementation of getpid() in the kernel should not
be difficult, just return the id of currently executing
process...?

sorry for the obscurity, I solved my problem some other way,
but still think getpid() would be useful.

Pavel.



Message has 1 Reply:
  Re: getpid?
 
(...) [code snipped] Ah, I understand. You could still use my method, but you'd have to pass the pid in as a parameter to the functions that need to know it, which would be ugly. (...) Well, get hacking! ;) (24 years ago, 14-Dec-00, to lugnet.robotics.rcx.legos)

Message is in Reply To:
  Re: getpid?
 
(...) AFAIK there aren't any built-in mechanisms. However, when a thread is launched, the launching process does get its PID as a return value from execi(). I'm thinking you could pass in a pointer to some storage in the argv, and then update that (...) (24 years ago, 14-Dec-00, to lugnet.robotics.rcx.legos)

7 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR