Search code examples
cprocesspthreadsthread-priority

Printing the priority of the main


I'm wondering if there is a way to print the priority of the main. In this question I asked how to print the deafult priority of a thread; now I'm very curious to know if it's possible to do the same for the main.


EDIT: my goal is to get the priority of the unique process I created (I'm using pthread library to create threads inside the int main block). The process should not be a normal process, but a real time process, so i cannot use the getpriority function. It can be used only for normal processes (source: pag. 183, Robert Love - Linux system programming - Talking directly to the kernel and C library (2013, O'Reilly Media) 2nd Ed).

How can I get the priority of the real time process and print it?


Solution

  • to print the priority of the main

    getpriority can be used to query the niceness level of a process.

    shed_getparam can be used to query the scheduling priority of a process.

    pthread_getschedparam can be used to query scheduling priority of a thread.

    How can I get the priority of the real time process and print it?

    A real time process is typically understood as a process running with SCHED_FIFO or SCHED_RR scheduling policy.

    You can use the same functions as above.

    so i cannot use the getpriority function. It can be used only for normal processes

    You can use getpriority on any process. (I think niceness level is just ignored in case of real-time scheduling, and this could be meant).