Mac OS crash, details inside...

Jacob Carlborg doob at me.com
Fri Jun 14 00:06:15 PDT 2013


On 2013-06-13 19:42, Gary Willoughby wrote:
> I get a program crash each time running the following code on MacOS 10.8
> (Lion). It seems to run ok on Ubuntu 12.04:
>
> import core.sys.posix.sys.stat;
> import core.sys.posix.unistd;
> import std.c.stdio;
> import std.c.stdlib;
> import std.process;
> import std.stdio;
> import std.string;
> import std.file;
>
> int main(string[] args)
> {
>      pid_t pid, sid;
>
>      pid = fork();
>      if (pid < 0)
>      {
>          exit(EXIT_FAILURE);
>      }
>
>      if (pid > 0)
>      {
>          exit(EXIT_SUCCESS);
>      }
>
>      umask(0);
>
>      sid = setsid();
>      if (sid < 0)
>      {
>          exit(EXIT_FAILURE);
>      }
>
>      if ((core.sys.posix.unistd.chdir("/")) < 0)
>      {
>          exit(EXIT_FAILURE);
>      }
>
>      close(STDIN_FILENO);
>      close(STDOUT_FILENO);
>      close(STDERR_FILENO);
>
>      auto logFile = File("/home/gary/Desktop/test.log", "a");
>      logFile.writeln("Reading file");
>
>      string command = format("logger -t %s %s", "hello", "This is a test");
>      executeShell(command);
>
>      logFile.writeln("Done");
>
>      return 0;
> }

You do know that you usually don't have a /home/ directory on Mac OS X? 
On Mac OS X it's called /Users/.

BTW, running that on Mac OS X 10.6.3 does not cause a crash. Although it 
doesn't seem to print or write anything.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list