Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90945106
getcpuid.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Nov 6, 07:06
Size
720 B
Mime Type
text/x-c
Expires
Fri, Nov 8, 07:06 (2 d)
Engine
blob
Format
Raw Data
Handle
22165182
Attached To
R2915 eSCT pipeline interoperability
getcpuid.c
View Options
#include "getcpuid.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/*
* This code is adapted from an example at:
* http://brokestream.com/procstat.html
*/
int
get_cpu_id
()
{
/* Get the the current process' stat file from the proc filesystem */
FILE
*
procfile
=
fopen
(
"/proc/self/stat"
,
"r"
);
long
to_read
=
8192
;
char
buffer
[
to_read
];
int
read
=
fread
(
buffer
,
sizeof
(
char
),
to_read
,
procfile
);
fclose
(
procfile
);
// Field with index 38 (zero-based counting) is the one we want
char
*
line
=
strtok
(
buffer
,
" "
);
for
(
int
i
=
1
;
i
<
38
;
i
++
)
{
line
=
strtok
(
NULL
,
" "
);
}
line
=
strtok
(
NULL
,
" "
);
int
cpu_id
=
atoi
(
line
);
return
cpu_id
;
}
Event Timeline
Log In to Comment