General
cancel
Showing results for 
Search instead for 
Did you mean: 

how to get current process in hpux11 dlkm

SOLVED
Go to solution
kaijile
Frequent Advisor

how to get current process in hpux11 dlkm

I'm developing dlkm now on HP-UX 11.11i
in my kernel module i want to get the current process ,such as linux's macro "current"
how to get current process in hpux11 dlkm?
40 REPLIES
Dennis Handly
Acclaimed Contributor

Re: how to get current process in hpux11 dlkm

What would be the current process if you have a N way machine? The one that is doing the I/O?

You want to supply more info on what you are trying to do.
Laurent Menase
Honored Contributor

Re: how to get current process in hpux11 dlkm

on 11.23:
thread id:
kt_tid(u.u_kthreadp);

process id
p_pid(u.uprocp);


don't forget to include sys/user.h
kaijile
Frequent Advisor

Re: how to get current process in hpux11 dlkm

I want to get the current process's struct proc and struct kthread descriptor,how to get their pointer?

how to traversing all struct proc and struct kthread descriptors in kernel ?

kt_tid is ok ,but when i used p_pid(u.uprocp);
have compile error :
cc: "test.c", line 187: error 1588: "uprocp" undefined

where is the variabe u defined?

bash-4.0# uname -a
HP-UX rp5470 B.11.11 U 9000/800 142444635 unlimited-user license

Laurent Menase
Honored Contributor
Solution

Re: how to get current process in hpux11 dlkm

u.u_procp
sorry for the typo
Laurent Menase
Honored Contributor

Re: how to get current process in hpux11 dlkm

it is in
/usr/include/machine/sys/user.h I believe.
it is a struct user defined in
/usr/include/sys/user.h
kaijile
Frequent Advisor

Re: how to get current process in hpux11 dlkm

kt_tid(u.u_kthreadp);

p_pid(u.uprocp);

I can't find these two functions in the
HP-UX 11i v1 Driver Development Guide and
HP-UX 11i v1 Driver Development Reference Guide


which Documentation has mentioned p_pid() and
kt_tid() function?

Laurent Menase
Honored Contributor

Re: how to get current process in hpux11 dlkm

they are defined in kthread_iface.h and proc_iface.h
Else I don't know. may be in 11i v2 dd ref guide
Laurent Menase
Honored Contributor

Re: how to get current process in hpux11 dlkm

but what are you trying to make exactly?

a kill calls logger?
kaijile
Frequent Advisor

Re: how to get current process in hpux11 dlkm

i want to traversing all struct proc and struct kthread descriptors in kernel,
but i can not find suitable kernel API function to do it.
in HP-UX 11i v1 Driver Development Guide and
HP-UX 11i v1 Driver Development Reference Guide
i can not find related information
Laurent Menase
Honored Contributor

Re: how to get current process in hpux11 dlkm

from user level you have pstat_getproc funcs
else in the kernel:
proc_pstat_idx_lookup_hold
proc_pstat_lookup_next_hold

- don(t forget to call proc_release()



Laurent Menase
Honored Contributor

Re: how to get current process in hpux11 dlkm

then once you have the proc you can look at its threads with
kt=p_firstthreadp(p)
then you can use kt_nextp(kt)


Then release the hold.
Laurent Menase
Honored Contributor

Re: how to get current process in hpux11 dlkm

be carefull that walking all procs and threads can take time. So be carefull to schedyield()
2 process walk.
kaijile
Frequent Advisor

Re: how to get current process in hpux11 dlkm

Is proc_list have lock?
what's the name of proc_list's lock?
how to use proc_list's lock ?
Laurent Menase
Honored Contributor

Re: how to get current process in hpux11 dlkm

proc_pstat_idx_lookup_hold
proc_pstat_lookup_next_hold

- don(t forget to call proc_release()

the hold and release is for that
kaijile
Frequent Advisor

Re: how to get current process in hpux11 dlkm

In kernel, i have the pid of the process,
how to get absolute path name of the executable file?
Laurent Menase
Honored Contributor

Re: how to get current process in hpux11 dlkm

In fact I don't see any easy way
Dennis Handly
Acclaimed Contributor

Re: how to get current process in hpux11 dlkm

>how to get absolute path name of the executable file?

Here is how to use pstat(2) calls to get it outside the kernel, not sure if that helps:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1350198
Laurent Menase
Honored Contributor

Re: how to get current process in hpux11 dlkm

in kernel no public API permit to find it.
kaijile
Frequent Advisor

Re: how to get current process in hpux11 dlkm

what are the functions pstat_stub32() and pstat() return value?

q4> disassemble pstat_stub32
Dump of assembler code for function pstat_stub32:
0x8b5678 : ldw 4(%r26),%ret0
0x8b567c : extrw,s %ret0,0,1,%ret0
0x8b5680 : stw %ret0,0(%r26)
0x8b5684 : stw %r0,8(%r26)
0x8b5688 : stw %r0,0x10(%r26)
0x8b568c : stw %r0,0x18(%r26)
0x8b5690 : ldw 0x24(%r26),%ret0
0x8b5694 : extrw,s %ret0,0,1,%ret0
0x8b5698 : ldil L'0x9a000,%r31
0x8b569c : be 0x358(%sr4,%r31)
0x8b56a0 : stw %ret0,0x20(%r26)
End of assembler dump.
q4> disassemble pstat|more
Dump of assembler code for function pstat:
0x9a358 : std %rp,-0x10(%sp)
0x9a35c : ldo 0x80(%sp),%sp
0x9a360 : mfia %r26
0x9a364 : addil L'-0x800,%r26,%r1
0x9a368 : ldo 0x7f8(%r1),%r26
0x9a36c : addil L'-0x10e000,%dp,%r1
0x9a370 : ldd 0x10(%r1),%r25
0x9a374 : ldd 0x440(%r25),%r24
Laurent Menase
Honored Contributor

Re: how to get current process in hpux11 dlkm

usually a pointer to current process uarea pointing to
first param come from
/usr/include/sys/pstat/pstat_ops.h
second is a pointer to a user space buffer
3rd and 4th as defined in manpage of pstat_*

not easy to use in your context because 2nd param is a pointer to current process user space.


Laurent Menase
Honored Contributor

Re: how to get current process in hpux11 dlkm

and the second parameter is a pointer to the current process data space.
kaijile
Frequent Advisor

Re: how to get current process in hpux11 dlkm

Another method:
I get a executing file's vnode,how to get the full path name?
Laurent Menase
Honored Contributor

Re: how to get current process in hpux11 dlkm

in fact it is the difficult part.
kaijile
Frequent Advisor

Re: how to get current process in hpux11 dlkm

bash-4.0# ps -ef |grep kwd
root 4692 4691 0 12:46:57 pts/0 0:01 kwdb -q4 /stand/vmunix /dev/kmem
root 4812 4768 1 13:18:16 pts/2 0:00 grep kwd
bash-4.0# lsof -p 4692
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
kwdb64 4692 root cwd DIR 64,0x3 8192 2 /
kwdb64 4692 root txt REG 64,0x7 18579168 31290 /usr (/dev/vg00/lvol7)
kwdb64 4692 root mem REG 64,0x7 12288 917 /usr (/dev/vg00/lvol7)
kwdb64 4692 root mem REG 64,0x7 1126400 899 /usr (/dev/vg00/lvol7)
kwdb64 4692 root mem REG 64,0x7 127445 112 /usr (/dev/vg00/lvol7)
kwdb64 4692 root mem REG 64,0x7 12288 107 /usr (/dev/vg00/lvol7)
kwdb64 4692 root mem REG 64,0x7 1863680 103 /usr (/dev/vg00/lvol7)
kwdb64 4692 root mem REG 64,0x7 155648 992 /usr/lib/dld.sl
kwdb64 4692 root 0u STR 157,0 0t1417 1530 /dev/pts/0->ldterm->ptem->pts
kwdb64 4692 root 1u STR 157,0 0t1417 1530 /dev/pts/0->ldterm->ptem->pts
kwdb64 4692 root 2u STR 157,0 0t1417 1530 /dev/pts/0->ldterm->ptem->pts
kwdb64 4692 root 3u REG 64,0x1 18800752 1623 /stand (/dev/vg00/lvol1)
kwdb64 4692 root 4r REG 64,0x1 18800752 1623 /stand (/dev/vg00/lvol1)
kwdb64 4692 root 5u STR 157,0 0t1417 1530 /dev/pts/0->ldterm->ptem->pts
kwdb64 4692 root 6u CHR 3,0x1 0x4a5ca7ac 68 /dev/kmem
kwdb64 4692 root 7u CHR 3,0 0t12467720 69 /dev/mem
kwdb64 4692 root 8r REG 64,0x1 18800752 1623 /stand (/dev/vg00/lvol1)
kwdb64 4692 root 9w REG 64,0x8 0 5350 /var/tmp/aaaa04692


why lsof can't show the full path of kwdb?

sometimes it's ok ,can show full path of kwdb