I basically want to inform main that a client disconnected in order to decrement the thread counter. Right now my program is setup to only create a certain number of threads to serve the connecting clients. If the client disconnects the thread count needs to be decremented so that it does not max out and not allow further threads to be made for waiting clients.
Now I can use a global variable, but I am doing this to learn more about Unix system programming and I thought either pipes or message queues would be interesting to try out. My problem is I am not sure how my code can utilize this to send information from child thread to main thread.
I wrote some quick and dirty code as an to test out different ways of what I need to do.
In my code I commented where I want to send message back to main process.
I have client code if you do need I can post, but the code below should be sufficient.
Hi all,
I'm trying to write a program that has some data it wants to send through a filter program(in this case tr), and then recieve the output from that filter program. The way I'm trying to do it is by setting up two pipes between the programs and piping the data in through one pipe and back... (2 Replies)
Hi,
I am stuck up with a strange problem.
I am writing an application - a kinda tracker that reads data from memcache and invokes theads to process each record of the memcache.
I dont want to join all my threads because my tracker should poll the cache in regular intervals say sum 300... (2 Replies)
i have a parent process and 5 child process.
As soon as the parent process is completed the 5 child processes need to start simultaneously (like multithreading)
All I need to do in a shell script
the child process is a function
can any one help me on this
thanks in advance (1 Reply)
Hi guys, I'm having some problem here, I'm studying pipes, and i want to create a shell in C and at this point a don't want to use semaphores, instead I want to use tricks. Straight to the doubt: I've a parent and a child process, and both of them has some code to execute, and the child process... (5 Replies)
Parent Thread Of Child Thread
Suppose a process creates some threads say threadC and threadD.
Later on each of these threads create new child threads say threadC1, threadC2, threadC3 etc. So a tree of threads will get created.
Is there any way to find out the parent thread of one such... (1 Reply)
Hi all,
Can I create multiple threads using single thread_id
like
pthread_t thread_id;
pthread_create(&thread_id, NULL, &print_xs, NULL);
pthread_create(&thread_id, NULL, &print_ys, NULL);
pthread_create(&thread_id, NULL, &print_zs, NULL);
pthread_join(thread_id, NULL);
what... (2 Replies)
Hi!
I am writing a C program that will create a child, child will create a thread and the thread will send a message to a unnamed pipe and will print the message before exiting.
here is my work:
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include... (6 Replies)
What is the best way for a parent to kill a child thread that has blocked on a command it cannot finish and will never read another line of its code? Will pthread_cancel() work with a thread that will never stop processing its current line of code? Thanks. (4 Replies)
Hi,
I am trying my hand in networking programming in C, and got stuck in piping.
I was following some tutorial and did the forking like :
while (1)
{
newsockfd = accept(sockfd,
(struct sockaddr *) &cli_addr, &clilen);
if (newsockfd < 0)
... (4 Replies)
I would like to know is there any we can kill a single thread among multiple threads belongs to process?
Since Signal action is process wise not per thread, i strongly feel that we can not or for that mater from external sources as well single thread can not be killed which is critical section... (2 Replies)
Discussion started by: murali242512
2 Replies
LEARN ABOUT DEBIAN
explain_listen
explain_listen(3) Library Functions Manual explain_listen(3)NAME
explain_listen - explain listen(2) errors
SYNOPSIS
#include <libexplain/listen.h>
const char *explain_listen(int fildes, int backlog);
const char *explain_errno_listen(int errnum, int fildes, int backlog);
void explain_message_listen(char *message, int message_size, int fildes, int backlog);
void explain_message_errno_listen(char *message, int message_size, int errnum, int fildes, int backlog);
DESCRIPTION
These functions may be used to obtain explanations for errors returned by the listen(2) system call.
explain_listen
const char *explain_listen(int fildes, int backlog);
The explain_listen function is used to obtain an explanation of an error returned by the listen(2) system call. The least the message will
contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail.
The errno global variable will be used to obtain the error value to be decoded.
This function is intended to be used in a fashion similar to the following example:
if (listen(fildes, backlog) < 0)
{
fprintf(stderr, "%s
", explain_listen(fildes, backlog));
exit(EXIT_FAILURE);
}
The above code example is available pre-packaged as the explain_listen_or_die(3) function.
fildes The original fildes, exactly as passed to the listen(2) system call.
backlog The original backlog, exactly as passed to the listen(2) system call.
Returns:
The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their
argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other
threads.
Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library.
explain_errno_listen
const char *explain_errno_listen(int errnum, int fildes, int backlog);
The explain_errno_listen function is used to obtain an explanation of an error returned by the listen(2) system call. The least the mes-
sage will contain is the value of strerror(errnum), but usually it will do much better, and indicate the underlying cause in more detail.
This function is intended to be used in a fashion similar to the following example:
if (listen(fildes, backlog) < 0)
{
int err = errno;
fprintf(stderr, "%s
", explain_errno_listen(err, fildes, backlog));
exit(EXIT_FAILURE);
}
The above code example is available pre-packaged as the explain_listen_or_die(3) function.
errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces-
sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter
the value of errno.
fildes The original fildes, exactly as passed to the listen(2) system call.
backlog The original backlog, exactly as passed to the listen(2) system call.
Returns:
The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their
argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other
threads.
Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library.
explain_message_listen
void explain_message_listen(char *message, int message_size, int fildes, int backlog);
The explain_message_listen function may be used to obtain an explanation of an error returned by the listen(2) system call. The least the
message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail.
The errno global variable will be used to obtain the error value to be decoded.
This function is intended to be used in a fashion similar to the following example:
if (listen(fildes, backlog) < 0)
{
char message[3000];
explain_message_listen(message, sizeof(message), fildes, backlog);
fprintf(stderr, "%s
", message);
exit(EXIT_FAILURE);
}
The above code example is available pre-packaged as the explain_listen_or_die(3) function.
message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread
safe.
message_size
The size in bytes of the location in which to store the returned message.
fildes The original fildes, exactly as passed to the listen(2) system call.
backlog The original backlog, exactly as passed to the listen(2) system call.
explain_message_errno_listen
void explain_message_errno_listen(char *message, int message_size, int errnum, int fildes, int backlog);
The explain_message_errno_listen function may be used to obtain an explanation of an error returned by the listen(2) system call. The
least the message will contain is the value of strerror(errnum), but usually it will do much better, and indicate the underlying cause in
more detail.
This function is intended to be used in a fashion similar to the following example:
if (listen(fildes, backlog) < 0)
{
int err = errno;
char message[3000];
explain_message_errno_listen(message, sizeof(message), err,
fildes, backlog);
fprintf(stderr, "%s
", message);
exit(EXIT_FAILURE);
}
The above code example is available pre-packaged as the explain_listen_or_die(3) function.
message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread
safe.
message_size
The size in bytes of the location in which to store the returned message.
errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces-
sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter
the value of errno.
fildes The original fildes, exactly as passed to the listen(2) system call.
backlog The original backlog, exactly as passed to the listen(2) system call.
SEE ALSO listen(2)
listen for connections on a socket
explain_listen_or_die(3)
listen for connections on a socket and report errors
COPYRIGHT
libexplain version 0.52
Copyright (C) 2008 Peter Miller
explain_listen(3)