Hi all, i write a little program that could be useful if you have DtraceToolkit. Almost all scripts wait until you press ctrl+c key, but
If want to automate this task this is not possible because you need to stay in front of your terminal. Ktime launch the program passed as parameter and wait <time> ( in seconds) until send a ctr+c signal ( SIGINT) to the child process. http://kbradero.neuroaio.biz/gnu/ktime/ktime.c ( source code online ) http://kbradero.neuroaio.biz/gnu/ktime/solaris/ binary Examples : ./ktime shortlived.d 20 Syntaxis: ./ktime <program> <time> #crontab -l * * * * * /tmp/test/DTraceToolkit-0.99/Bin/mon.sh You could integrate in other scripts: /tmp/test/DTraceToolkit-0.99/Bin/>#cat mon.sh #!/bin/bash cd /tmp/test/DTraceToolkit-0.99/Bin/ /tmp/test/DTraceToolkit-0.99/Bin/ktime errinfo 20 > state.txt echo `date` >> state.txt The code: cat ktime.c #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> /* Author: Jorge Alberto Garcia Gonzalez email: jorge.garcia.gonzalez(en)gmail.com Usage: ./ktime shortlived.d 10 ktime <program > <program parameters> <seconds until send ctrl+c > way to compile: gcc ktime.c -o ktime */ int main( int argc, char *argv[]){ pid_t child_pid=0; char *arguments=NULL; int narguments= argc-2; /* chid arguments*/ int i=argc-1 ; int element=1; int lenarg=0; for( element=1; element <=argc-2 ;element++){ lenarg+= strlen(argv[ element ]) +1 ; printf("%d \n",lenarg); } lenarg+=1; element=1; arguments=(char *) malloc( lenarg * sizeof(char) ); for( element=1; element <=argc-2 ; element++ ){ strcat( arguments, argv[ element ] ); strcat( arguments, " "); /* printf("argumento: %s \n", argv[ element ] ); */ } /* printf("child arguments: %s \n", arguments ); */ if( ( child_pid=fork() )==0 ){ //execl("/tmp/test/DTraceToolkit-0.99/Bin/errinfo","errinfo",(char *)0); execv(argv[1],&arguments ); }else { sleep( atoi(argv[argc-1]) ) ; kill(child_pid,SIGINT) ; //printf("child: %d is dead, leaving...\n",(int)child_pid); } return 0; }
_______________________________________________ dtrace-discuss mailing list [email protected]
