如何强制linux只运行我的C ++程序? [英] How to force linux only runs my C++ program?

查看:122
本文介绍了如何强制linux只运行我的C ++程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试建造一个机器人。我编写了一个C ++代码,用于识别用户的语音命令并执行一些操作(显示图像/视频,或说出该命令的答案)。因此,我使用Ubuntu-server 16.04,使用openbox窗口管理器来完成此操作,我的程序成功运行。



但我的问题是:我该如何自动完成?我的意思是,现在,我必须在启动我的主板之后去终端(我使用基于ARM的主板),然后去我的程序cd / home / m /然后通过./my-program执行它。但我喜欢这种情况自动发生!我的意思是我的程序在启动后自动运行。



此外,我喜欢当用户打开我的机器人,它显示我的徽标,然后显示我的C ++代码的默认图像,然后识别用户的声音,并做一个相关的对它的动作,这将再次像循环一样重复(默认图像,用户的命令识别,动作,默认图像,用户的命令识别,动作,再次......)。



我选择了Linux服务器,因为我不喜欢桌面或任何其他常见应用程序。我只喜欢我的操作系统在启动时运行我的程序,用户没有任何能力与机器人交互,否则语音命令!



我不知道如何配置我的Linux这样做?



我尝试了什么:



我搜索了它,发现它叫做Kiosk Linux。但每个教程都在讨论网络浏览器信息亭。而且我认为其中很多都已过时(对我不起作用)。我不喜欢我的Linux在启动时运行firefox,我喜欢它运行我的C ++代码!



我也是Linux的新手,不太了解它和需要一个简单的教程!

解决方案

阅读:如何在Linux启动时自动运行应用程序 [ ^ ]


最简单方法是将命令添加到 /etc/rc.local (文件/位置取决于分发但Ubuntu使用它;如果它不存在则创建它)。那么你可能想要使用shell的& 运算符(在行尾分隔的空格)以后台模式运行你的程序:

< pre lang =text> / path_to_app [options]&



如果应用程序使用X11,您可以告诉X11启动您的应用程序。例如,参见 Xsession - Debian Wiki [ ^ ]和 CustomXSession - Ubuntu Wiki [ ^ ]。再次使用shell的& 运算符。



如果应用程序不使用X11(例如直接写入时)到帧缓冲区),它也可以使用运行级脚本作为服务启动。这是kiosk模式中无窗口系统的常用方法,但需要编写运行级脚本并确定(取决于Linux发行版使用的方法)。



这些是我想到的方法,但还有更多。





空闲时显示图像应由应用程序处理。它也可能在启动时显示您的徽标。



如果要在系统启动时显示徽标,则必须更改启动启动图像。这取决于所使用的系统和分配,并且是一项高级任务,因为它必须在启动过程中尽早完成,并且需要SPI显示准备就绪。



或者,您可以检查是否可以使用 Plymouth - Ubuntu Wiki [ ^ ](这可能很棘手,因为你必须已经启动并运行了你的SPI显示器)。



Quote:

我也是Linux的新手,对它不太了解,需要一个简单的教程!

我们都开始一次没有或很少知识。但是你通常必须了解你在做什么,而不是仅仅从教程中进行压缩,至少应该知道关于shell和(对于你的项目)启动和启动过程的基础知识。这尤其适用于不是标准桌面,服务器或经常使用的系统(如Raspberry Pi),因此无需修改即可使用许多源(如教程)。


I am trying to build a robot. I have written a C++ code that recognizes user's voice commands and does some actions (showing an image/video, or saying an answer to that command). So, I used Ubuntu-server 16.04, with openbox window manager to do this, and my program runs on it successfully.

But my question is: How can I do it automatically? I mean, at now, I must going to terminal after booting my board(I use an ARM-based board), then go where my program is "cd /home/m/ " then execute it by "./my-program". But I liked this happened automatically! I mean my program become running automatically after boot.

Also I like when user turns on my robot, it shows my Logo, then shows a default image from my C++ code, then recognizes the user voice and does a related action to it and this will repeat like a loop again(default image, user's command recognition, does action, default image, user's command recognition,does action, and again...).

I chose Linux-server because I didn't like to have desktop or any other common applications. I only like my OS runs my program at startup and user has no any ability to interact with the robot, else the voice commands!

I don't know how can I configure my Linux to doing this?

What I have tried:

I searched for it and found that it called Kiosk Linux. But every tutorials are talking about web browser kiosks. and I think many of them are out dated(didn't work for me). I do not like my Linux runs firefox at startup, I like it runs my C++ code!

Also I am newbie in Linux and don't know much about it and need a straightforward tutorial!

解决方案

Read this : How to Autorun application at the start up in Linux[^]


The simplest method is adding the command(s) to /etc/rc.local (file/location depends on the distribution but Ubuntu uses that; create it if it does not exist). Then you probably want to run your program in background mode using the shell's & operator (space separated at the end of the line):

/path_to_app [options] &


If the application uses X11, you can tell X11 to start your application. See for example Xsession - Debian Wiki[^] and CustomXSession - Ubuntu Wiki[^] . Again use the shell's & operator.

If the application does not use X11 (e.g. when it writes directly to the frame buffer), it can be also started as service using a run level script. This is the common method for window less systems in kiosk mode but requires writing a run-level script and confuring that (depends on the method used by the Linux distribution).

These are the methods that come to my mind but there are more.


Showing an image when idle should be handled by the application. It may also show your logo when started.

If you want to show your logo when the system is powered up, you have to change the boot splash image. That depends on the used system and distribution and is an advanced task because it must be done as early as possible in the boot process and requires the SPI display to be ready.

Alternatively you can check if you can use Plymouth - Ubuntu Wiki[^] (it might be tricky because you must have your SPI display already up and running).

Quote:

Also I am newbie in Linux and don't know much about it and need a straightforward tutorial!

We all started once with no or little knowledge. But you usually have to understand what you are doing instead of just coyping from a tutorial and should at least know the very basics about the shell and (for your project) the boot and startup process. This applies especially to your system which is not a standard desktop, server, or often used (like the Raspberry Pi) so that many sources (like tutorials) can't be used without modification.


这篇关于如何强制linux只运行我的C ++程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆