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 / 1552
1551  |  1553
Subject: 
Re: getpid?
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Thu, 14 Dec 2000 02:41:19 GMT
Viewed: 
1135 times
  
On Wed, 13 Dec 2000, Pavel Petrovic wrote:

I am looking for a way how to obtain an identifier of a calling
thread/process... I have to distinguish between different threads
in the code and thus missing some equivalent to UNIX-like

  thr_self() / pthread_self() / getpid()

any ideas/tricks how to easily implement this in legOS?

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 storage in the calling thread once execi()
returns. Something like: (Not tested or even compiled, not guaranteed to
work AT ALL!)

int *pidptr = malloc(sizeof(int));
int pid = execi(MyFunction, 0, (char **)pidptr, PRIO_NORMAL,
DEFAULT_STACK_SIZE);
*pidptr = pid;

You would probably want to include some kind of way to indicate to
MyFunction just when the pointer becomes valid. Implementing that is left
as an exercise to the reader. :) Anyway, I hope this helps. Just out of
curiosity, why do you need this?

--
"Say not, 'I have found the truth,' but rather, 'I have found a truth.'
"Say not, 'I have found the path of the soul.' Say rather, 'I have met the
soul walking upon my path.'" -- Khalil Gibran
Mike Ash - <http://www.mikeash.com/>, <mailto:mail@mikeash.com>



Message has 1 Reply:
  Re: getpid?
 
(...) 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 (...) (24 years ago, 14-Dec-00, to lugnet.robotics.rcx.legos)

Message is in Reply To:
  getpid?
 
Hello, I am looking for a way how to obtain an identifier of a calling thread/process... I have to distinguish between different threads in the code and thus missing some equivalent to UNIX-like thr_self() / pthread_self() / getpid() any (...) (24 years ago, 13-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