LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Is running a standalone browser in Ubuntu still limited user? (https://www.linuxquestions.org/questions/linux-software-2/is-running-a-standalone-browser-in-ubuntu-still-limited-user-4175735752/)

pan64 04-11-2024 01:09 PM

Quote:

Originally Posted by JASlinux (Post 6495106)
You can put a standalone portable in a system folder, but they can also be most other locations.
When you put a browser out of the system, it will commonly not run with restricted permissions, logically, when it will run as root.

That is just wrong. The permissions of a process depends on the user who started, not on the location (where is it stored).
Again, all of the processes inherit permissions/rights/ownership from the parent process (where they were started from). Only root has right to modify it. The location of the binary is completely irrelevant.
The access to any file/dir depends on the current user and group (of the process, which wanted to access it), and the access rights of the given path.

teckk 04-11-2024 03:29 PM

Simple Example:

A stand alone executable. This will run as the user who ran the executable. Doesn't matter what directory it it in.

cpuload.c
Code:

//gcc cpuload.c -o cpuload

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>

static int cores = 2; //Set number of cpu cores here for cpu usage

static void cpu_load() {
    static long last_user, last_nice, last_sys;
    long user, nice, sys;
    char id[16];

    FILE * const fp = fopen( "/proc/stat", "r" );

    fscanf(fp, "%s %ld %ld %ld", id, &user, &nice, &sys);
    fclose(fp);

    char *percent = malloc(256);
    int per;
    sprintf(percent, "%ld\n",
        (user + nice + sys) - (last_user + last_nice + last_sys));
    sscanf(percent, "%d", &per);
    printf("%s%d\n", "Percent CPU Usage : ", per / cores);

    last_user = user;
    last_nice = nice;
    last_sys = sys;
}

int main(void)
{
    assert( sysconf(_SC_CLK_TCK) == 100 );
    for(;;) {
        cpu_load();
        sleep(1);
        printf("\033[2J\033[1;1H");
    }
}

Run that executable. Then in another shell:
Code:

ps a -o pid,tty,etime,cmd,user


All times are GMT -5. The time now is 03:15 AM.