| Marina, te llevaste todas las respuestas contigo |
| command line paramaters |
Display
int main ( int argc, char ** argv ) {
for ( j = 0 ; j < argc ; j ++ )
printf ( "\targv[%d] : (%s).\n", j, argv [ j ] ) ;
Help
if ( argc > 1 ) {
if ( strcmp( argv[1], "?" ) == 0 ) {
printf ( "Please contact {%s}.\n", Autor ) ;
exit( 0 ) ;
} ;
} ;
|
| daemon | if ( fork() <> 0 ) then exit() ; |
| display a HEX value, 8 digit | printf ( "(0x%8.8X).\n", HexVal ) ; |
| display a String | printf ( "unknown field id (%.8s).\n", szTAG ) ; |
| errno | use perrno() or strerror(errno) |
| identify the code | static char * kszAutor = "Robot Bellido, v 1.1" ; |
| mutex | use pthread_mutex_lock()
(sample : tp760:suse72:/home/sebas/progs/cstq/cstq.c) |
| pid | use getpid() (and #include </sys/types.h>) |
| random numbers | use srandom() and random ()
(sample : tp760:suse72:/home/sebas/progs/random/ran.c) |
| semaphores | use sem_init(), sem_post(), sem_wait(), sem_destroy() - POSIX.
(sample : tp760:suse72:/home/sebas/progs/cstq/cstq.c) See Unix history. |
| sockets |
On the client, use connect() : (sample : tp760:suse72:/home/sebas/progs/tcpclients) (sample : tp770:e:\sebas\linux\progs\panel\sebas\panelcli.c) (sample : t30:f:\linux\progs\panel\sebas\panelcli.c)
(sample : tp770:d:/eines/rexx/sockets/tutor/tmp/sebas/mserver.cmd) (sample : tp770:e:\sebas\linux\progs\panel\sebas\panelsrv.c) (sample : t30:f:\linux\progs\panel\sebas\panelsrv.c)
|
| threads |
use pthread_create( & TCB )
Under RH 6.2 I got errno = EINTR : Interrupted System Call in thread blocked at "recv()", so I moved to SuSE 7.2 and got it fixed. (sample : \\t400\linux\progs\threads/th.c) To use pthread library in linux environment, you must include pthread.h and compile the source code with -lpthread option. -lpthread means link to libpthread.so gcc th.c -o th -lpthread
|
| timeout |
use sigaction() and alarm()
in handle_sigalrm, use alarm() again ! (sample : tp760:suse72:/home/sebas/progs/timeout/to.c) (sample : t30:f:/linux/progs/timeout/subto.c) |
| timeout (sub-second) | start a thread that does nanosleep()
(sample : tp760:suse72:/home/sebas/progs/timeout/tsrv.c) |
| time of the day | Define
#include <time.h>
void LeeHora ( char * pszHora )
{
time_t MiTiempo ;
MiTiempo = time ( NULL ) ;
strftime ( pszHora, 10, "%T", localtime ( & MiTiempo ) ) ;
} ;
and use
char szMiTiempo [ 11 ] ;
LeeHora ( szMiTiempo ) ;
(sample : tp760:suse72:/home/sebas/progs/timeout/to.c) |
| write system/user log | configure /etc/syslog.conf :
LOCAL5.debug /var/log/sebas.log
use openlog() and syslog() (sample : tp760:suse72:/home/sebas/progs/writelog/writelog.c) |
-lxxx means to link a library named libxxx, so with gcc -lpthread -lrt -lc project1.c -o out you're telling it to link libpthread, librt and libc.
(-) are not catchable by sigaction.
1) SIGHUP 2) SIGINT (a) 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL (-) 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM 17) SIGCHLD 18) SIGCONT 19) SIGSTOP (-) 20) SIGTSTP 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR 31) SIGSYS
Linux supports nearly every signal provided by SVR4, BDS and POSIX, with few exceptions ("The Linux Programmer's Guide", Sven Goldt, v 0.4, March 1995) :
echo $SHELL
and
echo ${SHELL}
|
|
Site under construction. |
|
Actualitzat el 20130114 (a).
|
|