a Process ID

bridged with qdn.public.qnxrtp.porting
Post Reply
Jeff Holtz

a Process ID

Post by Jeff Holtz » Wed Aug 14, 2002 6:55 pm

I'm porting a QNX4 app to QNX6 and has a class which was used in two
seperate threads (Now converted to pthreads) In one section of code I had
the following:

pid_t pid = qnx_name_locate(0,"my_thread",0,NULL);
if (pid == CurrentPid() )
<Do something>
else
<Do something else>


In otherwords I have something like:
If your in a thread named 'my_thread' do one thing, else do something
else
how would I do this in QNX6. I can't seem to find a way to get the pid of a
specific process.

PS: the original qnx_name_attach(0,"my_thread") has now been changed to
name_attach(NULL,"my_thread",0);

--
Jeffrey B. Holtz
Software Engineering
Electro Scientific Industries, Inc.
Ph: 734-332-7054
Fax: 734-332-7077
email: holtzj@esi.com

Robert Krten

Re: a Process ID

Post by Robert Krten » Wed Aug 14, 2002 7:07 pm

Jeff Holtz <holtzj@esi.com> wrote:
I'm porting a QNX4 app to QNX6 and has a class which was used in two
seperate threads (Now converted to pthreads) In one section of code I had
the following:

pid_t pid = qnx_name_locate(0,"my_thread",0,NULL);
if (pid == CurrentPid() )
Do something
else
Do something else
In otherwords I have something like:
If your in a thread named 'my_thread' do one thing, else do something
else
how would I do this in QNX6. I can't seem to find a way to get the pid of a
specific process.

PS: the original qnx_name_attach(0,"my_thread") has now been changed to
name_attach(NULL,"my_thread",0);
Hmmm... since you've now converted it to threads, one assumes that you
did that with a pthread_create. One of the parameters to pthread_create()
is a thread_id that can be filled with the thread ID of the newly created
thread. If you were to use that in conjunction with pthread_self() (I think)
you could test which thread you were. Or, you can pass a parameter to
the newly created threads, effectively a flag indicating the "do this" or
"do something else" part...

Cheers,
-RK

--
Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at www.parse.com.
Email my initials at parse dot com.

Xiaodan Tang

Re: a Process ID

Post by Xiaodan Tang » Wed Aug 14, 2002 7:22 pm

Jeff Holtz <holtzj@esi.com> wrote:
I'm porting a QNX4 app to QNX6 and has a class which was used in two
seperate threads (Now converted to pthreads) In one section of code I had
the following:

pid_t pid = qnx_name_locate(0,"my_thread",0,NULL);
if (pid == CurrentPid() )
Do something
else
Do something else
In otherwords I have something like:
If your in a thread named 'my_thread' do one thing, else do something
else
how would I do this in QNX6. I can't seem to find a way to get the pid of a
specific process.

PS: the original qnx_name_attach(0,"my_thread") has now been changed to
name_attach(NULL,"my_thread",0);
Look at ConnectServerInfo(), it returns you the infomation of the
server, that the fd (returned from name_open()) point to.

However, I am not sure you can name_open() yourself, cause that needs
special flag (_RESMGR_FLAG_SELF) on attach, unless of cause, the proc
did something special for you.

-xtang

Post Reply

Return to “qdn.public.qnxrtp.porting”