Hi All,
Attached is a program to work on the "shared mutex" concept.
It was working fine earlier. Now after running up2date on the system,
the same program fails (hangs up). Any ideas as to the possible cause
for this problem ?
------
cat /etc/redhat-release
Red Hat Enterprise Linux WS release 3 (Taroon Update 3)
------
Any inputs are appreciated.
Thanks & Regards,
Tushar
Krishna Monian wrote:
Hi All,
I am in the process of writing a file logging utility
under Linux that monitors every file that is accessed
(read, create, delete, failed access). It is something
similar to the FileMon app on the sysinternals site.
The way I am thinking of doing this is by rerouting
system calls and performing the necessary logging.
However the sysinternals site mentioned that this
method will not work under the 2.6 kernel.
Are there any other ways to go about doing this? As of
now I do not need compatibility with the 2.6 kernel,
but might need it in the future. It would be nice if I
could write something that was compatible with future
releases.
If not upto which kernel version will the system call
hook method work? Will it be backward compatible and
if so upto which version?
Thanks
Krishna
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail
_______________________________________________
Redhat-devel-list mailing list
Redhat-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/redhat-devel-list
#include <sys/ipc.h>
#include <sys/shm.h>
#if defined(linux)
#include <sys/time.h>
#endif /* linux */
#include <stdio.h>
#include <pthread.h>
/* Usage:
pthread loop yes
loop: the number of loops the program will run
yes: print out detail messages
*/
main( int argc, char *argv[] )
{
int id;
char *mem;
pthread_cond_t *p_cond;
pthread_mutex_t *p_mutex;
key_t key=0;
int cnt=0, loop=0, parent_pid=0, child_pid=0;
if ( argc > 1 )
loop=atoi(argv[1]);
else
printf("Usage: pthread loop yes\n");
printf("The test starts\n");
parent_pid=getpid();
key= key + parent_pid;
while ( cnt++ < loop )
{
key+=200000;
printf("LOOP %d \n", cnt);
id=shmget(key, 1024, IPC_CREAT | 0666);
if ( id== -1 )
{ printf("shmget failed\n");
exit(2);
}
mem=shmat(id, (char *)0x10000000, 0);
if ( mem== (char*)-1 )
{ printf("shmat failed\n");
exit(2);
}
p_cond=mem+16;
p_mutex=mem+48;
/* initialize mutex */
{
pthread_mutexattr_t attr;
if (pthread_mutexattr_init(&attr))
exit(4);
if (pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED))
{
printf("pthread_mutexattr_setpshared failed\n");
pthread_mutexattr_destroy(&attr);
exit(5);
}
if (pthread_mutex_init(p_mutex, &attr))
{
printf("pthread_mutex_init failed\n");
pthread_mutexattr_destroy(&attr);
exit(5);
}
}
/* initialize cond variable */
{
pthread_condattr_t cvAttr;
if (pthread_condattr_init(&cvAttr))
exit(3);
if (pthread_condattr_setpshared(&cvAttr, PTHREAD_PROCESS_SHARED) ||
pthread_cond_init(p_cond, &cvAttr) ||
pthread_condattr_destroy(&cvAttr))
{
pthread_condattr_destroy(&cvAttr);
exit(6);
}
}
if ( (child_pid=fork()) > 0 )
{
printf("proc1 lock mutex\n");
pthread_mutex_lock(p_mutex);
sprintf(mem,"aaaaa");
printf("proc1 pthread_cond_wait\n");
pthread_cond_wait(p_cond, p_mutex);
printf("proc1 is waken up %d\n", cnt);
pthread_mutex_unlock(p_mutex);
strcpy(mem, "bbbbb");
waitpid(child_pid,NULL,NULL);
}
else
{
char cmd[80];
int err=0, ppid=0, count=0;
struct timeval tpstart, tpend;
/* sync, wait for parent process ready */
while ( mem[0] != 'a' )
sched_yield();
ppid=atoi(mem+1);
/* wake up parent process */
printf("proc2 locking\n");
pthread_mutex_lock(p_mutex);
printf("proc2 signal waiter %d\n", cnt);
err=pthread_cond_signal(p_cond);
printf("ret code of psignal: %d\n", err);
pthread_mutex_unlock(p_mutex);
/* check parent process has been waken up */
gettimeofday(&tpstart,NULL);
while ( mem[0] != 'b' )
{
sched_yield();
gettimeofday(&tpend,NULL);
if ( (tpend.tv_sec - tpstart.tv_sec) > 120 )
{
printf("FAILED, parent process is not waken up, kill parent process\n");
printf("the test failed in loop %d\n", cnt);
sprintf(cmd, "kill -9 %d", parent_pid);
system(cmd);
exit(1);
}
}
exit(0);
}
if ( shmdt((char *)0x10000000) != 0 )
{ printf("shmdt failed\n");
exit(1);
}
if ( shmctl(id, IPC_RMID, NULL) != 0 )
{ printf("ipcrm failed\n");
exit(1);
}
}
printf("The test end with loop %d\n", cnt);
return(0);
}
_______________________________________________
Redhat-devel-list mailing list
Redhat-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/redhat-devel-list