public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* PROBLEM: fork() & setpriority()
@ 2005-07-11 10:58 Rommer
  2005-07-11 11:07 ` Arjan van de Ven
  0 siblings, 1 reply; 3+ messages in thread
From: Rommer @ 2005-07-11 10:58 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 204 bytes --]

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

[-- Attachment #2: test.c --]
[-- Type: text/x-csrc, Size: 739 bytes --]

#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;
}

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-07-11 11:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-11 10:58 PROBLEM: fork() & setpriority() Rommer
2005-07-11 11:07 ` Arjan van de Ven
2005-07-11 11:14   ` Rommer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox