Linux / Unix

Obtain a list of process scheduling policy and priority

Normally, you can read the file /proc/[pid]/sched and get the related information. But since I am using a simplified one, the sched file is not presented. And I need to figure out another way to get it. I finally found there is a C library, <sched.h>, to do that. You can find the following declarations in the library.

In this case, we only need sched_getparam() to obtain scheduling priority and sched_getscheduler() to obtain scheduling policy.
(more…)

How to get the number / id of processes and threads?

Since I am working on Hi3518 with Linux, in order to reduce the use of computing power of the device, I used a simplified version of Linux. So, most of the applications are gone or are simplified without any option. I just summarized the methods I can use on Hi3518 and should be also work on some other Embedded Linux.

In fact, the applications in Linux usually obtain related information by reading the files in /proc. Under /proc, you can see a lot of folder, some of them are in numbers. Those folders named in numbers, which are process ids (PIDs) represent the processes run in the system. Thus, you can see the details of each process in each folder.

/proc/***/

where *** are the corresponding process pid.
(more…)

Embedded Linux: 如何讓海思Hi3518開機後自動執行Shell Script?

我目前正於海思平台上進行開發,芯片是Hi3518E,Linux的內核是使用海思SDK所提供的代碼去編譯,所以我想以下所說的,大概跟其他海思芯片是差不多的吧(既然是同一家公司的,工程師做的東西應該都差不多才對吧),不過還是以Hi3518為準~

已經了解了Hi3518一段時間,目前需要它於開機啟動時自動插入一些驅動和程序,所以小小研究了一下要怎麼做。首先,因為有一系列的指令要做,所以就給它寫了個Shell Script(腳本),讓它可以一次過運行我所有的指令,之後再放入Startup。至於Shell Script要怎麼寫,我暫時就不多說了,因為我知的也不多~ 哈哈~

0. 基礎知識

/etc/init.d/ : init.d 是一個用來存放Unix/Linux Shell Script的文件夾,如果你的內核有開啟 init.d 的話,系統啟動時,會在登入前自行執行存放在這裡的腳本。一般系統上所有服務的啟動腳本都會放在這裡,一般是Linux系統的話,應該都會看到它的蹤影。
(more…)