amit_shriv
asked on
sched_getaffinity error no is 14???
I am using function int sched_getaffinity(pid_t pid, unsigned int len, unsigned long *mask);
and the value return is -1. The errorno is 14 EFAULT. How should I fix this?
and the value return is -1. The errorno is 14 EFAULT. How should I fix this?
ASKER
Actulayy I am using this function in Delphi and I have converted as
type
PCardinal = ^cardinal;
function sched_getaffinity(pid: cardinal; len: cardinal;var mask: PCardinal): Integer; cdecl;
type
PCardinal = ^cardinal;
function sched_getaffinity(pid: cardinal; len: cardinal;var mask: PCardinal): Integer; cdecl;
hi,
maybe you treat the mask parameter as a value and not as a pointer to a value and so the memory address is invalid?
maybe you treat the mask parameter as a value and not as a pointer to a value and so the memory address is invalid?
ASKER
Pointer to a value means pass by reference??
If yes then in delphi VAR indicated the parameter is passed by reference.
If yes then in delphi VAR indicated the parameter is passed by reference.
what happens if you remove the var keyword or keeping var but define mask as cardinal instead of PCardinal?
ASKER
in both the case retune value is -1 with errorno 14.
and can you tell what is the value of mask you pass?
ASKER
I don't pass anything but even if I pass 1 then the same return value -1 and one more thing the mask value remain 1 after the function is executed.
I suppose this "1" is treated like a pointer. Can you try to pass a pointer and not a direct value.
ASKER
Sorry I couldn't understand. What you mean by pointer and not direct value.
Could you post some parts of your code, including where you call sched_getaffinity method?
ASKER
This code I have defined in one file
pid_t = Integer;
function sched_getaffinity(pid: pid_t; len: Cardinal; var mask: Cardinal): Integer; cdecl;
the other file comtains
hCurrentProcessHandle: Integer;
dwProcessAffinity: Cardinal;
dwProcessAffinitySize: Cardinal;
ReturnValue: Integer;
dwProcessAffinitySize := Sizeof(dwProcessAffinity);
hCurrentProcessHandle := getpid;
ReturnValue := sched_getaffinity(hCurrent ProcessHan dle, dwProcessAffinitySize, dwProcessAffinity);
pid_t = Integer;
function sched_getaffinity(pid: pid_t; len: Cardinal; var mask: Cardinal): Integer; cdecl;
the other file comtains
hCurrentProcessHandle: Integer;
dwProcessAffinity: Cardinal;
dwProcessAffinitySize: Cardinal;
ReturnValue: Integer;
dwProcessAffinitySize := Sizeof(dwProcessAffinity);
hCurrentProcessHandle := getpid;
ReturnValue := sched_getaffinity(hCurrent
ASKER
Since dwProcessAffinity is pass by reference so I have not initialize it.
Hm, by looking to this page: http://www.die.net/doc/linux/man/man2/sched_getaffinity.2.html
I think that the mask parameter has to have some value and its significance is described in the link. There is also written that "Usually, all bits in the mask are set." so you can try to set all bits to 1.
Also I think it's better to remove var keyword and try to pass a pointer.
I think that the mask parameter has to have some value and its significance is described in the link. There is also written that "Usually, all bits in the mask are set." so you can try to set all bits to 1.
Also I think it's better to remove var keyword and try to pass a pointer.
ASKER
I tried by using pointers and set all the bits to1 but still the return value is -1.
Could you post the modified code?
ASKER
This code I have defined in one file
pid_t = Integer;
PCardinal = ^Cardinal;
function sched_getaffinity(pid: pid_t; len: Cardinal; mask: PCardinal): Integer; cdecl;
other file:
hCurrentProcessHandle: Integer;
dwProcessAffinity: PCardinal;
dwProcessAffinitySize: Cardinal;
ReturnValue: Integer;
dwProcessAffinitySize := Sizeof(dwProcessAffinity);
hCurrentProcessHandle := getpid;
ReturnValue := sched_getaffinity(hCurrent ProcessHan dle, dwProcessAffinitySize, dwProcessAffinity);
pid_t = Integer;
PCardinal = ^Cardinal;
function sched_getaffinity(pid: pid_t; len: Cardinal; mask: PCardinal): Integer; cdecl;
other file:
hCurrentProcessHandle: Integer;
dwProcessAffinity: PCardinal;
dwProcessAffinitySize: Cardinal;
ReturnValue: Integer;
dwProcessAffinitySize := Sizeof(dwProcessAffinity);
hCurrentProcessHandle := getpid;
ReturnValue := sched_getaffinity(hCurrent
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot WelkinMaze for the help.
For nothing. :)
Did you get it working?
Did you get it working?
ASKER
yep it's working great :)...
Great! I'm glad I've helped you. :)
ASKER
Thanks :)
EFAULT
A supplied memory address was invalid
Apparently you are passing some incorrect memory address as parameter to sched_getaffinity.
Also you can use perror() to print the error message.
Cheers!
sunnycoder