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: How to run a shell script at startup on Hisilicon’s Hi3518?

I am now developing on a Hisilicon’s chip, Hi3518E. The Linux kernal is built and compiled from the code of the SDK provided by Hisilicon. Thus, I think what I am going to say is also valid for other chips from Hisilicon.

I have studied Hi3518 for a few months. I now want to load some drives and programs at startup automatically so I spent some time to figure out how to do it on this chip. First of all, since I needed to run a set of commands, I wrote a Shell Script to organize all the commands together. Thus,I can run them all when I run the script once. Then, put the script into startup. I am not going to talk about how to write a Shell script as I don’t really know much about it.

0. Basic Knowledge

/etc/init.d/ : init.d is a folder for containing Unix/Linux Shell Scripts. If you enabled init.d in your kernal, the system will load and run the scripts placing here when it turns on. In common, all the init scripts of the services needed in a system are placed in this folder. So, you should find it on almost every Linux.
(more…)