Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    pausing the server

    I have a client and server (for multiple client) program which are communicating through UNIX domain sockets(AF_UNIX).These are simple programs where the client is sending letters in small case to the server and the server returns the same letter in upper case.
    When i kill the client using SIGKILL all the resources of the client --
    like memory, socket files,etc are released .. And the server closes the connection for that particular client..
    But I dont want the server to close that connection I want it to pause itself whenever the client is killed. I mean I want the server to remain in the same connection even if the client is killed.
    How can I do this ???
    plz help me out since this is part of my project..
    plz utter request to help

  2. #2
    Just Joined!
    Join Date
    Feb 2012
    Hyderabad, India
    Why don't you use UDP. There is no connection. just send and receive. For your case UDP should work.

  3. #3
    Quote Originally Posted by vedasolutions View Post
    Why don't you use UDP. There is no connection. just send and receive. For your case UDP should work.
    As I said earlier I am working on AF_UNIX sockets and it is a part of my project .So,I cant make use of UDP sockets. Actaully I am working on Checkpoint/Restart mechanism for AF_UNIX sockest and therefore when the client is checkpointed and when it is killed I dont want the server to close that connection but just hold that connection so that when the client is again restarted it will just communicate with the server with same connection . I dont want the server to release the connection when the client is killed.
    Please help me out.. I am trying to do this from long but unable to do so ..
    Please help me

  4. $spacer_open
  5. #4
    as said earlier to hold the connection on the server i have written a kernel module
    So, to hold the server i have just passed on the server in a waiting queue.. the code(module) is -->

    pid of the server is passed to the module
    here sk-> returns the pid of the client and when the client is killed i have just tried to put the server in waiting queue.

    #include <linux/init.h>
    #include <linux/module.h>
    #include <linux/fs.h>
    #include <linux/pid.h>
    #include <linux/net.h>
    #include <linux/sched.h>
    #include <linux/fdtable.h>
    #include "/usr/src/linux-"
    #include "/usr/src/linux-"

    unsigned int pidnr;
    int pid=0;
    module_param(pidnr, uint, 0644);

    struct scull_pipe {
    wait_queue_head_t inq, outq; /* read and write queues */
    char *buffer, *end; /* begin of buf, end of buf */
    int buffersize; /* used in pointer arithmetic */
    char *rp, *wp; /* where to read, where to write */
    int nreaders, nwriters; /* number of openings for r/w */
    struct fasync_struct *async_queue; /* asynchronous readers */
    struct semaphore sem; /* mutual exclusion semaphore */
    struct cdev cdevchar; /* Char device structure */

    static ssize_t scull_p_read (struct task_struct *task,struct file *filp,size_t count)//, char _ _user *buf, size_t count,loff_t *f_pos)
    struct scull_pipe *dev = filp->private_data;

    if (down_interruptible(&dev->sem))
    return -ERESTARTSYS;

    while (!pid/*dev->rp = = dev->wp*/) { /* nothing to read */
    up(&dev->sem); /* release the lock */
    if (filp->f_flags & O_NONBLOCK)
    return -EAGAIN;
    PDEBUG("\"%s\" reading: going to sleep\n", task->comm);
    if (wait_event_interruptible(dev->inq, !pid/*(dev->rp != dev->wp)*/))
    return -ERESTARTSYS; /* signal: tell the fs layer to handle it */
    /* otherwise loop, but first reacquire the lock */
    if (down_interruptible(&dev->sem))
    return -ERESTARTSYS;
    /* ok, data is there, return something */
    if (pid)//dev->wp > dev->rp)
    count = min(count, (size_t)(dev->wp - dev->rp));
    else /* the write pointer has wrapped, return data up to dev->end */
    count = min(count, (size_t)(dev->end - dev->rp));
    if (copy_to_user(buf, dev->rp, count)) {
    up (&dev->sem);
    return -EFAULT;
    dev->rp += count;
    if (dev->rp = = dev->end)
    dev->rp = dev->buffer; /* wrapped */
    up (&dev->sem);

    /* finally, awake any writers and return */
    // PDEBUG("\"%s\" did read %li bytes\n",current->comm, (long)count);
    return count;
    int mod_init(void)
    struct file *file;
    struct socket *sock;
    int fd = 0;
    struct inode *inode;
    struct sock *sk;
    struct task_struct *task;
    struct files_struct *files;
    for_each_process(task) {
    if ( task->pid == pidnr) {
    printk("%s[%d]\n", task->comm, task->pid);

    files = task->files;

    file = fcheck_files(files, fd);
    while(file) {
    inode = file->f_path.dentry->d_inode;
    if (S_ISSOCK(inode->i_mode)) {
    sock = file->private_data;
    printk("\ntype = %d\n", sock->type);
    printk("\n sk_peercred_pid=%d",sk->;
    file = fcheck_files(files, fd);

    return 0;
    void mod_exit(void)




    but this code is currently not working .. I want to know whether my idea for holding the server is correct or not and whether this code will serve the purpose of holding the connection on the server?? And if the code is incorrect what may be the method to do so??

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts