办法
编写程序运行shell脚本,将脚本 copy 到 /etc/profile.d 目录。机器开机启动时会自动执行 /etc/profile.d 目录下的所有shell脚本。
Demo
~/ 目录下创建test.cpp测试程序。
//code needs to run
#include<stream>
using namespace std;
int main()
{
cout << "Test For Setting Start!!!" << endl;
return 0;
}
将test.cpp编译为可执行程序。
g++ test.cpp -o test
~/ 目录下创建test.sh测试shell脚本。
#!/bin/sh
gnome-terminal -x bash -c 'cd ~/;./test; exec bash'
最后为test.sh添加权限,并copy到 /etc/profile.d 目录,重启机器观察现象。
本文介绍了如何编写C++程序并编译成可执行文件test,接着创建shell脚本test.sh,设置其执行权限并将脚本复制到/etc/profile.d以确保机器启动时自动运行。通过这个过程,展示了如何将程序逻辑与系统启动流程结合。

被折叠的 条评论
为什么被折叠?



