PROBLEM: fork() & setpriority()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I have trouble with fork() and setpriority().
When priority of child process != priority of parent process
and used SIGCHLD handler.
See example.

kernel 2.6.12.1, no SMP

--
Best regards, Roman
#include <sys/time.h>
#include <sys/types.h>
#include <sys/resource.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

struct sigaction sa_chld;
int i = 0;


static void chld_handler (int signum) {
    int status = 0;
    wait (&status);
    printf ("child closed: status = %i\n", status >> 8);
}


void test (void) {
    pid_t pid = fork ();

    if (pid == 0) {
	setpriority (PRIO_PROCESS, 0, 0);
	printf ("helo from child, i = %i\n", i);
	exit (i);
    }
}


int main () {
    memset (&sa_chld, 0, sizeof (sa_chld));
    sa_chld.sa_handler = &chld_handler;
    sigaction (SIGCHLD, &sa_chld, NULL);

    setpriority (PRIO_PROCESS, 0, -1);
    while (1) {
	i++;
	test ();
	sleep (3);
    }
    return 0;
}

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]
  Powered by Linux