• C

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?
amit_shrivAsked:
Who is Participating?
 
WelkinMazeConnect With a Mentor Commented:
I think you have to get the size of cardinal here instead the size of the pointer
dwProcessAffinitySize := Sizeof(Cardinal);

and also define one other cardinal variable and make all of its bits to be 1s
then make dwProcessAffinity to point to the new variable
and try again
0
 
sunnycoderCommented:
Show some code

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
0
 
amit_shrivAuthor Commented:
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;
0
Managing Security Policy in a Changing Environment

The enterprise network environment is evolving rapidly as companies extend their physical data centers to embrace cloud computing and software-defined networking. This new reality means that the challenge of managing the security policy is much more dynamic and complex.

 
WelkinMazeCommented:
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?
0
 
amit_shrivAuthor Commented:
Pointer to a value means pass by reference??
If yes then in delphi VAR indicated the parameter is passed by reference.
0
 
WelkinMazeCommented:
what happens if you remove the var keyword or keeping var but define mask as cardinal instead of PCardinal?
0
 
amit_shrivAuthor Commented:
in both the case retune value is -1 with errorno 14.
0
 
WelkinMazeCommented:
and can you tell what is the value of mask you pass?
0
 
amit_shrivAuthor Commented:
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.
0
 
WelkinMazeCommented:
I suppose this "1" is treated like a pointer. Can you try to pass a pointer and not a direct value.
0
 
amit_shrivAuthor Commented:
Sorry I couldn't understand. What you mean by pointer and not direct value.
0
 
WelkinMazeCommented:
Could you post some parts of your code, including where you call sched_getaffinity method?
0
 
amit_shrivAuthor Commented:
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(hCurrentProcessHandle, dwProcessAffinitySize, dwProcessAffinity);


0
 
amit_shrivAuthor Commented:
Since dwProcessAffinity is pass by reference so I have not initialize it.
0
 
WelkinMazeCommented:
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.
0
 
amit_shrivAuthor Commented:
I tried by using pointers and set all the bits to1 but still the return value is -1.
0
 
WelkinMazeCommented:
Could you post the modified code?
0
 
amit_shrivAuthor Commented:
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(hCurrentProcessHandle, dwProcessAffinitySize, dwProcessAffinity);
0
 
amit_shrivAuthor Commented:
Thanks a lot WelkinMaze  for the help.
0
 
WelkinMazeCommented:
For nothing. :)
Did you get it working?
0
 
amit_shrivAuthor Commented:
yep it's working great :)...
0
 
WelkinMazeCommented:
Great! I'm glad I've helped you. :)
0
 
amit_shrivAuthor Commented:
Thanks :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.