lkml.org 
[lkml]   [2005]   [Jul]   [11]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
/
DateMon, 11 Jul 2005 13:58:09 +0300
FromRommer <>
SubjectPROBLEM: fork() & setpriority()
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;
}
\
 
 \ /
  Last update: 2005-07-11 11:01    [from the cache]
©2003-2008