Linux 启动时运行c程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4424703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 00:17:46  来源:igfitidea点击:

run c program at startup

linux

提问by Alkesh

I am a beginner to linux programming. What I want to do is, run a C "Hello World" program at startup. Once the user logs in, run that C program. How can I achieve this?

我是 linux 编程的初学者。我想要做的是,在启动时运行一个 C 的“Hello World”程序。用户登录后,运行该 C 程序。我怎样才能做到这一点?

I am running Ubuntu 8.04.

我正在运行 Ubuntu 8.04。

回答by Neilvert Noval

I've done that on my machine.

我已经在我的机器上这样做了。

First, in your menu bar, click System, then Preferences, then click Sessions.

首先,在您的菜单栏中,单击System,然后Preferences,然后单击Sessions

A list of startup programs will be shown. click + button and add your script.

将显示启动程序列表。单击 + 按钮并添加您的脚本。

This might differ on linux distro. But at least you got the idea.

这在 linux 发行版上可能有所不同。但至少你明白了。

回答by Alkesh

I solved it by writing a bash script

我通过编写 bash 脚本解决了它

回答by thiagoh

you can create a script inside /etc/init.d/myScriptNamewhich inside this script you start you program

你可以创建一个脚本/etc/init.d/myScriptName,在这个脚本中你开始你的程序

remember to give chmod +xto your script to give execution permissions

记得给chmod +x你的脚本赋予执行权限