Hello,

Here is an example from chapter 5 of the book "Explore BeagleBone" by Derek 
Molloy:

#include<gnu/libc-version.h>
#include<sys/syscall.h>
#include<sys/types.h>
#include<iostream>
#include<signal.h>
using namespace std;

int main(){
   //gnu_get_libc_version() returns a string that identifies the 
   //glibc version available on the system.
   cout << "The GNU libc version is " << gnu_get_libc_version() << endl;

   // process id tid is thread identifier
   // look inside sys/syscall.h for System Call Numbers
   pid_t tid;    //pid_t is of type integer
   tid = syscall(SYS_gettid);   // make a system call to get the process id
   cout << "The Current PID is: " << tid << endl;
   //can also get by calling getpid() function from signal.h
   cout << "The Current PID is: " << getpid() << endl;

   // Can get current UserID by using: 
   int uid = syscall(SYS_getuid);
   cout << "It is being run by user with ID: " << uid << endl;
      // or getting the value from syscalls.kernelgrok.com
   uid = syscall(0xc7);
   cout << "It is being run by user with ID: " << uid << endl;

   return 0;
}



It isn't compiled:

debian@beaglebone:~/exploringbb/chp05/syscall$ g++ syscall.cpp -o syscall
syscall.cpp: In function ‘int main()’:
syscall.cpp:22:10: error: ‘syscall’ was not declared in this scope
    tid = syscall(SYS_gettid);   // make a system call to get the process id
          ^~~~~~~
syscall.cpp:22:10: note: suggested alternative: ‘swscanf’
    tid = syscall(SYS_gettid);   // make a system call to get the process id
          ^~~~~~~
          swscanf
syscall.cpp:25:38: error: ‘getpid’ was not declared in this scope
    cout << "The Current PID is: " << getpid() << endl;
                                      ^~~~~~
syscall.cpp:25:38: note: suggested alternative: ‘getpt’
    cout << "The Current PID is: " << getpid() << endl;
                                      ^~~~~~
                                      getpt
debian@beaglebone:~/exploringbb/chp05/syscall$

Indeed, I searched for syscall declaration in the toolchain ... and didn't 
find it:

debian@beaglebone:~/exploringbb/chp05/syscall$ sudo grep -rn 
/usr/include/arm-linux-gnueabihf/ -e "syscall("
[sudo] password for debian: 
debian@beaglebone:~/exploringbb/chp05/syscall$

Any comments ?

Thanks.

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to beagleboard+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beagleboard/b1ecb535-dd31-43de-9ecd-a5b527b37bb1o%40googlegroups.com.

Reply via email to