Linux RedHat kernel: what kernel is best?

  • andrushok
  • Novice
  • Novice
  • User avatar
  • Posts: 24

Post 3+ Months Ago

I installed RedHat 9 on some server and upgrade kernel up to newest version: kernel-smp-2.4.20-31.9 Some my application stopped working. I debugged it and found the following probem:

after fork() I try to lock file using lockf(). On child branch I lunch the new application using execl(). Usualy (on any Unix and RedHat 7.1) the child process keeps the lock. However, in this case the child process losses the lock and my application work wrong. :shock:

I downgraded kernel down to kernel-smp-2.4.20-28.9 and the appication started working fine.

I checked the bug list on http://www.redhat.com and found nothing about that. Does sombody hear about this problem?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • b_heyer
  • Web Master
  • Web Master
  • User avatar
  • Posts: 4581
  • Loc: Maryland

Post 3+ Months Ago

Most likely you are missing a module or package when you compiled the new kernel.
  • andrushok
  • Novice
  • Novice
  • User avatar
  • Posts: 24

Post 3+ Months Ago

What is the package did I miss? I downloades RPMs from ftp.redhat.com and installed it using rpm command. I did not compile kernels.

I have the tested code
Code: [ Select ]
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>

int main( int args, char* argv[])
{
    pid_t spid = getpid();
    if( args == 1 )
        printf( "\n\n[%d]: Parent process started\n", spid);
    else if( args == 3 )
    {
        printf( "[%d]: Child process started\n", spid);
        sleep( 15);
        
        printf( "[%d]: Child process done!!!\n", spid);

        return 0;
    }

    pid_t pid = fork();
  int status;

  switch( pid )
  {
  case -1:
        printf( "[%d] fork failed.\n", spid);
        exit( 0);

    case 0:
    {
            pid_t pid = getpid();
            printf( "[%d]->[%d] Child forked\n", spid, pid);

            int hOutFile = creat( "test.out", S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH
| S_IWOTH);

            int rl = lockf( hOutFile, F_LOCK, 100);
            if( !rl )
                printf( "[%d]->[%d] File 'test.out' locked\n", spid, pid);
            else
            {
                printf( "[%d]->[%d] File 'test.out' did not lock, process failed\n", spid
, pid);
                exit( 0);
            }

        if( execl( argv[0], argv[0], "-child", "-pending", NULL) == -1 )
        {
                printf( "[%d]->[%d] Execute '%s' failed\n", spid, pid, argv[0]);
                exit( 0);
        }
        }
    default:
printf( "[%d] Parent forked\n", spid);
        break;
    }
    printf( "[%d] Sleep 10 seconds.\n", spid);

    sleep( 10);
    printf( "[%d] Check lock (should be locked!).\n", spid);

    int hOutFile = open( "test.out", O_RDONLY);

    int rl = lockf( hOutFile, F_TEST, 100);
    printf( "[%d] Lock of file '%d' is %d.\n", spid, hOutFile, rl);

    printf( "[%d] Sleep 10 seconds.\n", spid);
    sleep( 10);

    printf( "[%d] Wake up!, check lock (should be NOT locked!).\n", spid);
    rl = lockf( hOutFile, F_TEST, 100);
    printf( "[%d] Lock of file '%d' is %d.\n", spid, hOutFile, rl);

    printf( "[%d] Parent Done!!!\n", spid);
    return 0;
}
  1. #include <fcntl.h>
  2. #include <unistd.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <sys/wait.h>
  8. int main( int args, char* argv[])
  9. {
  10.     pid_t spid = getpid();
  11.     if( args == 1 )
  12.         printf( "\n\n[%d]: Parent process started\n", spid);
  13.     else if( args == 3 )
  14.     {
  15.         printf( "[%d]: Child process started\n", spid);
  16.         sleep( 15);
  17.         
  18.         printf( "[%d]: Child process done!!!\n", spid);
  19.         return 0;
  20.     }
  21.     pid_t pid = fork();
  22.   int status;
  23.   switch( pid )
  24.   {
  25.   case -1:
  26.         printf( "[%d] fork failed.\n", spid);
  27.         exit( 0);
  28.     case 0:
  29.     {
  30.             pid_t pid = getpid();
  31.             printf( "[%d]->[%d] Child forked\n", spid, pid);
  32.             int hOutFile = creat( "test.out", S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH
  33. | S_IWOTH);
  34.             int rl = lockf( hOutFile, F_LOCK, 100);
  35.             if( !rl )
  36.                 printf( "[%d]->[%d] File 'test.out' locked\n", spid, pid);
  37.             else
  38.             {
  39.                 printf( "[%d]->[%d] File 'test.out' did not lock, process failed\n", spid
  40. , pid);
  41.                 exit( 0);
  42.             }
  43.         if( execl( argv[0], argv[0], "-child", "-pending", NULL) == -1 )
  44.         {
  45.                 printf( "[%d]->[%d] Execute '%s' failed\n", spid, pid, argv[0]);
  46.                 exit( 0);
  47.         }
  48.         }
  49.     default:
  50. printf( "[%d] Parent forked\n", spid);
  51.         break;
  52.     }
  53.     printf( "[%d] Sleep 10 seconds.\n", spid);
  54.     sleep( 10);
  55.     printf( "[%d] Check lock (should be locked!).\n", spid);
  56.     int hOutFile = open( "test.out", O_RDONLY);
  57.     int rl = lockf( hOutFile, F_TEST, 100);
  58.     printf( "[%d] Lock of file '%d' is %d.\n", spid, hOutFile, rl);
  59.     printf( "[%d] Sleep 10 seconds.\n", spid);
  60.     sleep( 10);
  61.     printf( "[%d] Wake up!, check lock (should be NOT locked!).\n", spid);
  62.     rl = lockf( hOutFile, F_TEST, 100);
  63.     printf( "[%d] Lock of file '%d' is %d.\n", spid, hOutFile, rl);
  64.     printf( "[%d] Parent Done!!!\n", spid);
  65.     return 0;
  66. }


The normal output is:
Code: [ Select ]
[10314]: Parent process started
[10314]->[10315] Child forked
[10314]->[10315] File 'test.out' locked
[10315]: Child process started
[10314] Parent forked
[10314] Sleep 10 seconds.
[10314] Check lock (should be locked!).
[10314] Lock of file '3' is -1.            (!!!!) this is fine!
[10314] Sleep 10 seconds.
[10315]: Child process done!!!
[10314] Wake up!, check lock (should be NOT locked!).
[10314] Lock of file '3' is 0.
[10314] Parent Done!!!
  1. [10314]: Parent process started
  2. [10314]->[10315] Child forked
  3. [10314]->[10315] File 'test.out' locked
  4. [10315]: Child process started
  5. [10314] Parent forked
  6. [10314] Sleep 10 seconds.
  7. [10314] Check lock (should be locked!).
  8. [10314] Lock of file '3' is -1.            (!!!!) this is fine!
  9. [10314] Sleep 10 seconds.
  10. [10315]: Child process done!!!
  11. [10314] Wake up!, check lock (should be NOT locked!).
  12. [10314] Lock of file '3' is 0.
  13. [10314] Parent Done!!!

However , if I applied the new kernel I have the following:
Code: [ Select ]
[10314]: Parent process started
[10314]->[10315] Child forked
[10314]->[10315] File 'test.out' locked
[10315]: Child process started
[10314] Parent forked
[10314] Sleep 10 seconds.
[10314] Check lock (should be locked!).
[10314] Lock of file '3' is 0.              (!!!!) ERROR!
[10314] Sleep 10 seconds.
[10315]: Child process done!!!
[10314] Wake up!, check lock (should be NOT locked!).
[10314] Lock of file '3' is 0.
[10314] Parent Done!!!
  1. [10314]: Parent process started
  2. [10314]->[10315] Child forked
  3. [10314]->[10315] File 'test.out' locked
  4. [10315]: Child process started
  5. [10314] Parent forked
  6. [10314] Sleep 10 seconds.
  7. [10314] Check lock (should be locked!).
  8. [10314] Lock of file '3' is 0.              (!!!!) ERROR!
  9. [10314] Sleep 10 seconds.
  10. [10315]: Child process done!!!
  11. [10314] Wake up!, check lock (should be NOT locked!).
  12. [10314] Lock of file '3' is 0.
  13. [10314] Parent Done!!!

What do I need to add to the new kernel to restore normal work according to POSIX standard?

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 65 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.