Thread: Threads in Linux!

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    12

    Exclamation Threads in Linux!

    hey!

    Im working on a imgviewer on linux, when I launch
    it from xterm it is using xterms's thread to
    recieve I/O. This is a problem, I want to
    use a separate thread and have it act as if
    I called the app using the & sign, like
    "./imgview &".

    How do I do this? I know some stuff about
    multithreaded apps but I dont think this is
    exactly what I want.

    All feedback is welcome!

    - Suddenad

  2. #2
    Registered User
    Join Date
    Oct 2002
    Posts
    12
    hey!

    is there any "hello world" like examples on how
    to do this?

    thanks for the feedback!

    - suddenad

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Code:
    int main(int argc, char *argv[])
    {
        pid_t pid;
        
        switch (pid = fork())
        {      
            case -1:    
                perror("fork");
                return (EXIT_FAILURE);
                break;
            case 0:
                sleep(1);
                if( setsid() == -1 )
                {
                    perror("setsid");
                }
                break;
            default:
                _exit(EXIT_SUCCESS);
                break;
        }
    
        /*
         * We have now forked and setup our own group, detached from the terminal
         */
    It's close to being complete.... I just hacked this out of an app, you can amend it to suit your needs
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Wireless Network Linux & C Testbed
    By james457 in forum Networking/Device Communication
    Replies: 3
    Last Post: 06-11-2009, 11:03 AM
  2. Replies: 1
    Last Post: 10-24-2005, 06:35 AM
  3. if you dont like linux threads, dont read...
    By ... in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 02-03-2003, 11:26 AM
  4. threads and linux
    By shaka87 in forum C Programming
    Replies: 1
    Last Post: 06-07-2002, 03:59 AM