Linux System calls in C on OSX

asky

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.

Celada

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Linux system calls vs C lib functions

From Dev

How to Mock Linux System Calls in C

From Dev

Concurrent system calls in Linux

From Dev

Linux:System calls for Who

From Dev

Same programm works in C, but not in C++ (uses linux system calls)

From Dev

C application that copy/moves a file & uses system calls in Linux

From Dev

C system calls fails

From Dev

C system calls open()

From Dev

Linux bare system calls, not glibc

From Dev

Assembly Linux system calls vs assembly OS x system calls

From Dev

Can you perform system calls from OSX Terminal?

From Java

System calls vs C/C++ system calls

From Dev

Which file system to use in between OSX and Linux

From Dev

Storing System Calls in C Programming

From Java

How many system calls are there in linux kernel 2.6?

From Dev

Can I use Linux system calls in android?

From Dev

Why are linux system calls different across architectures

From Dev

Basics questions regarding File and I/O System Calls in C (on Linux/UNIX)

From Java

Are function calls like read() , write() actual system calls in linux?

From Dev

How can I make Linux system calls from a C/C++ application, without using assembly, and in a cpu-independent manner?

From Dev

C: Suppress system calls from binary

From Dev

pipe stuck in read (C - system calls)

From Dev

Are ALL system() calls a security risk in c++?

From Dev

Calling C system calls from JNI

From Dev

Merging two text files into new one (back and forth every new line) using C in Linux using system-calls

From Dev

java reads file system file names differently on osx and linux

From Java

Why do some Linux system calls not have a wrapper, but are documented as if they do?

From Java

What are the Windows and Linux native OS/system calls made from malloc()?

From Java

Why do some Linux system calls have two man pages?

Related Related

  1. 1

    Linux system calls vs C lib functions

  2. 2

    How to Mock Linux System Calls in C

  3. 3

    Concurrent system calls in Linux

  4. 4

    Linux:System calls for Who

  5. 5

    Same programm works in C, but not in C++ (uses linux system calls)

  6. 6

    C application that copy/moves a file & uses system calls in Linux

  7. 7

    C system calls fails

  8. 8

    C system calls open()

  9. 9

    Linux bare system calls, not glibc

  10. 10

    Assembly Linux system calls vs assembly OS x system calls

  11. 11

    Can you perform system calls from OSX Terminal?

  12. 12

    System calls vs C/C++ system calls

  13. 13

    Which file system to use in between OSX and Linux

  14. 14

    Storing System Calls in C Programming

  15. 15

    How many system calls are there in linux kernel 2.6?

  16. 16

    Can I use Linux system calls in android?

  17. 17

    Why are linux system calls different across architectures

  18. 18

    Basics questions regarding File and I/O System Calls in C (on Linux/UNIX)

  19. 19

    Are function calls like read() , write() actual system calls in linux?

  20. 20

    How can I make Linux system calls from a C/C++ application, without using assembly, and in a cpu-independent manner?

  21. 21

    C: Suppress system calls from binary

  22. 22

    pipe stuck in read (C - system calls)

  23. 23

    Are ALL system() calls a security risk in c++?

  24. 24

    Calling C system calls from JNI

  25. 25

    Merging two text files into new one (back and forth every new line) using C in Linux using system-calls

  26. 26

    java reads file system file names differently on osx and linux

  27. 27

    Why do some Linux system calls not have a wrapper, but are documented as if they do?

  28. 28

    What are the Windows and Linux native OS/system calls made from malloc()?

  29. 29

    Why do some Linux system calls have two man pages?

HotTag

Archive