So I did a quick test and
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
int main (int argc, char *argv[]) {
printf("Hello World\n");
printf("%d\n",getpid());
}
compiled with gcc on my macbook pro running OSX 10.9.5 prints
Hello World
640
As I would expect it to on most linux distributions. I know the darwin kernel is based on UNIX, but will all the linux system calls behave exactly the same on OSX as they do on let's say Ubuntu? (I am aware the pid is different different times time I run it will be different, but that's not what I'm really talking about here). I also have Ubuntu installed on a small partition of my SSD, so if the answer is no, that's okay.
I would say that it is misleading to call getpid()
a "linux system call". That gives the impression that it is a Linux-specific system call, which it isn't. Actually, getpid()
and many other system calls are specified by POSIX, and you will find it implemented on both Linux and MacOS and on many other systems, with identical behaviour.
The majority of system calls or even C library functions you will use in typical software are specified by standards like POSIX and ANSI C, and you will them implemented with the same behaviour on many different operating systems. Portable software is software that keeps to this set of common system calls and functions that are widely available.
Linux also has Linux-specific system calls. MacOS also has MacOS-specific system calls. Neither of those will work on the opposite operating system, obviously. The manpages for such system calls will usually call out the fact that they are not portable. Furthermore, they exist quite often as low-level implementation details and most software need not use them, which makes it easier to keep most software portable.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments