Hi,
I’m having an interesting problem here…
In a small system monitoring program, I want to detect (for running processes) whether
the proc’s executable image has changed since the process was started.
To do so, I
- call qnx_psinfo(),
- call stat() for the returned un.proc.name[]
- compare psdata.un.proc.file_time to st.st_mtime
This work for almost all processes. That it doesn’t work for Fsys et.al. is ok,
but for one of our own programs, I see a difference of exactly one second.
Can You explain why this happens?
Below You will find a list of processes currently running on my machine, together
with their psinfo() and stat() times. The processes in question are marked ‘>>>’.
Thanks in advance.
PID psinfo() time stat() mtime Executable
4 ps: 0 st: 872093345 /bin/Fsys
5 ps: 0 st: 869144580 /bin/Fsys.aha7scsi
16 ps: 844452529 st: 844452529 //7/bin/Dev32
19 ps: 848595538 st: 848595538 //7/bin/Dev32.ansi
22 ps: 867421112 st: 867421112 //7/bin/Dev32.ser
23 ps: 844452392 st: 844452392 //7/bin/Dev32.pty
24 ps: 872028262 st: 872028262 //7/bin/Fsys.floppy
26 ps: 825352018 st: 825352018 //7/bin/Pipe
31 ps: 870384125 st: 870384125 //7/bin/Net
33 ps: 950805915 st: 950805915 //7/bin/Net.ether905
62 ps: 850934034 st: 850934034 //7/bin/cron
74 ps: 872270841 st: 872270841 //7/bin/Mouse
99 ps: 866052038 st: 866052038 //7/bin/tinit
102 ps: 867352685 st: 867352685 //7/usr/bin/lpsrvr
106 ps: 941036023 st: 941036023 //7/qnx4/photon/bin/phfontpfr
420 ps: 847402003 st: 847402003 //7/bin/ksh
552 ps: 847402003 st: 847402003 //7/bin/ksh
1811 ps: 936381493 st: 936381493 //7/qnx4/photon/bin/Photon
1820 ps: 940448272 st: 940448272 //7/qnx4/graphics/drivers/Null.ms
1822 ps: 937867519 st: 937867519 //7/qnx4/graphics/drivers/Pg.rage
1828 ps: 872100014 st: 872100014 //7/bin/Input
1832 ps: 937325268 st: 937325268 //7/qnx4/photon/bin/pwm
1837 ps: 872100014 st: 872100014 //7/bin/Input
1848 ps: 937324748 st: 937324748 //7/qnx4/photon/bin/pdm
1870 ps: 937325131 st: 937325131 //7/qnx4/photon/bin/pterm
1873 ps: 847402003 st: 847402003 //7/bin/ksh
1941 ps: 937324687 st: 937324687 //7/qnx4/photon/bin/helpviewer
5369 ps:1046915285 st:1046915285 //7/usr/fc6/bin/fccore
5378 ps: 847402003 st: 847402003 //7/bin/ksh
7629 ps: 972410351 st: 972410351 //7/usr/tcprt/5.0/usr/ucb/portmap
8567 ps: 937490183 st: 937490183 //7/usr/tcprt/5.0/usr/ucb/Dns
8619 ps: 980529729 st: 980529729 //7/usr/tcprt/5.0/usr/ucb/Tcpip
8635 ps: 945104289 st: 945104289 //7/usr/tcprt/5.0/usr/ucb/routed
8640 ps: 924271653 st: 924271653 //7/usr/tcprt/5.0/usr/ucb/inetd
8646 ps: 950886627 st: 950886627 //7/usr/tcprt/5.0/usr/ucb/lpd
8658 ps: 978533108 st: 978533108 //7/usr/tcprt/5.0/usr/ucb/Nfsd
8662 ps: 979668246 st: 979668246 //7/usr/tcprt/5.0/usr/ucb/NFSfsys
8669 ps: 979668246 st: 979668246 //7/usr/tcprt/5.0/usr/ucb/NFSfsys
8677 ps: 979668246 st: 979668246 //7/usr/tcprt/5.0/usr/ucb/NFSfsys
8684 ps: 910418395 st: 910418395 //7/qnx4/voyager/bin/voyager
8686 ps: 910419644 st: 910419644 //7/qnx4/voyager/bin/voyager.server
8991 ps: 910418569 st: 910418569 //7/qnx4/voyager/bin/vmail
10181 ps: 937325131 st: 937325131 //7/qnx4/photon/bin/pterm
10185 ps: 847402003 st: 847402003 //7/bin/ksh
12048 ps:1047470360 st:1047470360 //7/usr/fc6/bin/fcterm
12508 ps: 937325131 st: 937325131 //7/qnx4/photon/bin/pterm
12511 ps: 847402003 st: 847402003 //7/bin/ksh
12535 ps:1047458985 st:1047458985 //7/usr/fc6/bin/fcproc
12550 ps: 847402003 st: 847402003 //7/bin/ksh
13048 ps: 937325131 st: 937325131 //7/qnx4/photon/bin/pterm
14100 ps:1047470360 st:1047470360 //7/usr/fc6/bin/fcterm
14105 ps:1046915509 st:1046915510 //7/usr/fc6/bin/rtdb
14107 ps:1046915509 st:1046915510 //7/usr/fc6/bin/rtdb
14134 ps:1047035976 st:1047035976 //7/usr/fc6/bin/fcshlib
14656 ps: 965210252 st: 965210252 //7/usr/lib/vedit/vedit
14819 ps:1019042595 st:1019042595 //7/usr/bin/photon/Atom
16255 ps:1047473333 st:1047473333 //7/home/frk/stuff/qnx/psinfo/tst
22753 ps: 937325131 st: 937325131 //7/qnx4/photon/bin/pterm
25316 ps: 847402003 st: 847402003 //7/bin/ksh
25386 ps: 965210252 st: 965210252 //7/usr/lib/vedit/vedit
29435 ps: 937325131 st: 937325131 //7/qnx4/photon/bin/pterm
30461 ps: 937325131 st: 937325131 //7/qnx4/photon/bin/pterm
30464 ps: 847402003 st: 847402003 //7/bin/ksh
\
Here is the program which created above output:
#include <stdio.h>
#include <stdlib.h>
#include <sys/psinfo.h>
#include <sys/kernel.h>
#include <sys/stat.h>
int main()
{
struct _psinfo psdata;
struct stat st;
pid_t pid;
for ( pid = 1; pid < 32768; pid++ )
{
if ( pid <= 0 )
break;
if ( ( qnx_psinfo( PROC_PID, pid, &psdata, 0, 0 ) != -1 )
&& ( psdata.pid == pid )
&& ! ( psdata.flags & _PPF_VID )
&& ! ( psdata.flags & _PPF_MID )
&& ! stat( psdata.un.proc.name, &st ) )
printf( “%5d ps:%10d st:%10d %s\n”,
psdata.pid, psdata.un.proc.file_time,
st.st_mtime, psdata.un.proc.name );
}
return EXIT_SUCCESS;
}
–
T. Haupt
BitCtrl Systems GmbH
eMail: frk bitctrl de