[英]Start new mac terminal window with new process
我正在使用 fork() 创建新进程。
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <ncurses.h>
#include <iostream>
#include <time.h>
int main (void)
{
switch (fork())
{
case -1: exit(0);
case 0: {
execl("Terminal.app", "shell", "-e", "time ls; shell", (char*)0);
break;
}
default: {
std::cout << "OK" << std::endl;
initscr();
time_t secs = time(NULL);
tm* timeInfo = localtime(&secs);
printw("TIME: %s", asctime(timeInfo));
getch();
endwin();
}
}
return 0;
}
此代码应该创建新的控制台窗口并使time ls
,但它没有。 问题是什么?
使用命令open -an Terminal.app
运行应用程序的一个新实例(即使一个已经在运行)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.