?
Solved

sched_getaffinity error no is 14???

Posted on 2006-05-01
23
Medium Priority
?
231 Views
Last Modified: 2010-04-15
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?
0
Comment
Question by:amit_shriv
  • 12
  • 10
23 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 16583182
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
 

Author Comment

by:amit_shriv
ID: 16583613
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
 
LVL 11

Expert Comment

by:WelkinMaze
ID: 16584037
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:amit_shriv
ID: 16584067
Pointer to a value means pass by reference??
If yes then in delphi VAR indicated the parameter is passed by reference.
0
 
LVL 11

Expert Comment

by:WelkinMaze
ID: 16584120
what happens if you remove the var keyword or keeping var but define mask as cardinal instead of PCardinal?
0
 

Author Comment

by:amit_shriv
ID: 16584145
in both the case retune value is -1 with errorno 14.
0
 
LVL 11

Expert Comment

by:WelkinMaze
ID: 16584164
and can you tell what is the value of mask you pass?
0
 

Author Comment

by:amit_shriv
ID: 16584202
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
 
LVL 11

Expert Comment

by:WelkinMaze
ID: 16584209
I suppose this "1" is treated like a pointer. Can you try to pass a pointer and not a direct value.
0
 

Author Comment

by:amit_shriv
ID: 16584215
Sorry I couldn't understand. What you mean by pointer and not direct value.
0
 
LVL 11

Expert Comment

by:WelkinMaze
ID: 16584220
Could you post some parts of your code, including where you call sched_getaffinity method?
0
 

Author Comment

by:amit_shriv
ID: 16584242
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
 

Author Comment

by:amit_shriv
ID: 16584249
Since dwProcessAffinity is pass by reference so I have not initialize it.
0
 
LVL 11

Expert Comment

by:WelkinMaze
ID: 16584285
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
 

Author Comment

by:amit_shriv
ID: 16584437
I tried by using pointers and set all the bits to1 but still the return value is -1.
0
 
LVL 11

Expert Comment

by:WelkinMaze
ID: 16584597
Could you post the modified code?
0
 

Author Comment

by:amit_shriv
ID: 16585131
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
 
LVL 11

Accepted Solution

by:
WelkinMaze earned 2000 total points
ID: 16585197
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
 

Author Comment

by:amit_shriv
ID: 16585382
Thanks a lot WelkinMaze  for the help.
0
 
LVL 11

Expert Comment

by:WelkinMaze
ID: 16585415
For nothing. :)
Did you get it working?
0
 

Author Comment

by:amit_shriv
ID: 16585502
yep it's working great :)...
0
 
LVL 11

Expert Comment

by:WelkinMaze
ID: 16585511
Great! I'm glad I've helped you. :)
0
 

Author Comment

by:amit_shriv
ID: 16585567
Thanks :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question