Differences between OS X and Linux (C/C++)
OS X is Unix-based (like Linux) and follows POSIX (to some extent). If you use POSIX functions available in OS X, you should have no (or minimal at best) problems running the code under Linux.
The opposite is not true though, since Linux follows POSIX to a much higher degree and (almost) conforms to the newest POSIX standards, while OS X doesn't support the newer versions. Furthermore, GNU has many extensions both to POSIX tools and libraries that may not be available on OS X.
In short, under Linux you would have more up-to-date and feature-rich libraries to work with. However, the good-old functions of POSIX found in OS X are also available in Linux. So generally there shouldn't be a problem, so long as you stick to the standard behaviors.
Does OS X support POSIX sessions?
In my experience, Mac OSX does support posix sessions. The getsid()
system call works. But the ps
utility does not (ps -o sess
produces 0
for all processes).
How to identify which OS Python is running on?
>>> import os
>>> os.name
'posix'
>>> import platform
>>> platform.system()
'Linux'
>>> platform.release()
'2.6.22-15-generic'
The output of platform.system()
is as follows:
- Linux:
Linux
- Mac:
Darwin
- Windows:
Windows
See: platform
— Access to underlying platform’s identifying data
_wspawnl/_spawnl equivalent on Mac OS X or Linux
You can use fork
and execv
system call together in the following way :
if (!fork()){ // create the new process
execl(path, *arg, ...); // execute the new program
}
The fork
system call creates a new process, while the execv
system call starts the execution of the application specify in path.
For example, you can use the following function spawn
whose argument are the name of the application to be executed and the list of its arguments.
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int spawn (char* program, char** arg_list)
{
pid_t child_pid;
/* Duplicate this process. */
child_pid = fork ();
if (child_pid != 0)
/* This is the parent process. */
return child_pid;
else {
/* Now execute PROGRAM, searching for it in the path. */
execvp (program, arg_list);
/* The execvp function returns only if an error occurs. */
fprintf (stderr, “an error occurred in execvp\n”);
abort ();
}
}
int main ()
{
/* The argument list to pass to the “ls” command. */
char* arg_list[] = {
“ls”, /* argv[0], the name of the program. */
“-l”,
“/”,
NULL /* The argument list must end with a NULL. */
};
spawn (“ls”, arg_list);
printf (“done with main program\n”);
return 0;
}
This example has been taken from the chapter 3.2.2 of this book. (Really good reference for development in Linux).
Mac OS equivalent of the Windows Fibers API?
No, there is no equivalent on OS X (or most UNIX-based systems, for that matter). The ucontext
series of functions were deprecated by the POSIX standard and no replacement was provided.
The closest you can get on OS X is Grand Central Dispatch, which allows you to create dispatch queues that execute 'blocks' (essentially functions). Processing of these queues can be suspended and resumed, similar to fibers, though you can't stop and resume execution in the middle of a block.
There's also Boost.Context, which provides similar functionality to ucontext
(and perhaps even uses it internally), though it's a C++ library.
Related Topics
How to Build and Compile Cross Platform Xamarin Apps on Linux
Resizing The Image with Padding Using Convert on Ubuntu
Why How to Cast Sockaddr to Sockaddr_In
Difference Between Tcp_Max_Syn_Backlog and Somaxconn
Apache Webserver - How to Write to Dir/Files with Permissions Set at 755 Instead of 777
Upper Limit of File Descriptor in Linux
How to Get The UId of The Other End of a Unix Socket Connection
How to Install The Ncursesw Development Libraries
What Would It Take to Make Windows a Posix Compliant Operating System Out of The Box
Is There a Limit on Number of Tcp/Ip Connections Between MAChines on Linux
How to Restart a Service If Its Dependent Service Is Restarted
Gvim Redraw Issues with Virtual Box and Windows 7 Host
Which Linux Distribution Should I Use as a Xen Host
Recursively Kill R Process with Children in Linux
Fast String Search in a Very Large File
When "Vagrant Up" It Says "It Appears Your Machine Doesn't Support Nfs" (Debian Jessie)