a urgent help needed in C

Discussion in 'C' started by vignesh1988i, Mar 17, 2010.

  1. vignesh1988i

    vignesh1988i Banned

    Joined:
    Sep 19, 2009
    Messages:
    72
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Chennai
    How can END a process through a C program...... is there any function in C???????


    it's urgent :)


    thank s in advance
     
  2. karthigayan

    karthigayan New Member

    Joined:
    Feb 19, 2010
    Messages:
    33
    Likes Received:
    0
    Trophy Points:
    0
    Using the function kill() you can end the process ,for this you need the process id .The function raise() will end the current process .

    Code:
    man 2 kill
    man raise
    
    In the kill function you can send a signal as a second argument to end the process.There are various signals to do this like (SIGKILL,SIGSROT,SIGTERM,etc).
     
  3. vignesh1988i

    vignesh1988i Banned

    Joined:
    Sep 19, 2009
    Messages:
    72
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Chennai
    i think that is under LINUX.... i need in windows environment....... those functions (kill() & raise() ) will it work in DEV C++ compiler????????? :):nice:
     
  4. itstimetojazz

    itstimetojazz New Member

    Joined:
    Sep 9, 2009
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Hi

    Try using
    Exit(0);

    This will terminate ur calling process
     
  5. murugaperumal

    murugaperumal New Member

    Joined:
    Feb 20, 2010
    Messages:
    15
    Likes Received:
    1
    Trophy Points:
    0
    use the following function
    Code:
    exit(0) 
    
     
  6. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Help with you is always urgent. Why not try asking sooner? Don't leave it so long before tackling the task then you won't be as stressed out.
     
  7. vignesh1988i

    vignesh1988i Banned

    Joined:
    Sep 19, 2009
    Messages:
    72
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Chennai
    hmmm .. you are right.. :) ok.. can u help me out for my problem.... :)


    thank u
     
  8. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    It's not easy: you have to find the process's main window and post it a WM_CLOSE message. There are WinAPI functions to help you with this though; see EnumWindows.

    See also http://support.microsoft.com/kb/178893
     
  9. vignesh1988i

    vignesh1988i Banned

    Joined:
    Sep 19, 2009
    Messages:
    72
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Chennai
    oh... is it !!!! fine.... :) :) ..... wat about kill() function , whether we can we use that ........... I am having DEV C++ compiler.... whether kill() will work in my compiler???

    i saw that function in sys.h file.. i hope u know this :)

    int kill(pid_t pid, int sig);

    here 'sig' refers to the signal ... in Linux it's easy to get the signal no. which is equivalent to termination of that process corresponding to the given PID no. ... but how to find the same signal number for WINDOWS.... or we have same signal formats for all OS??? :)

    plz. help me out........ :)
     
  10. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28
  11. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Well you can try it. Get the PID from Task Manager, and the terminate signal is 9, so if the PID is 1000 the call would be kill(1000,9); If that terminates the process then it works; if not then it doesn't.

    The only way I can tell you if it works is to get DevC++ myself, install and test it, and since you already have it installed it's easier for you to do it.
     
  12. vignesh1988i

    vignesh1988i Banned

    Joined:
    Sep 19, 2009
    Messages:
    72
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Chennai
    hmmmm... :) i too tried that alsoo.. i included all header files like : sys/types.h , signal.h , even process.h..... it's showing the error as kill() not found... first added a header file :( as i have referred , all are saying kill() function is present in above mentioned one of these header file .... so still am searching where this kill() function is stored in DEV C++......

    so can u help me still :)

    thank u
    S.R.Vignesh
     
  13. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Probably it's a linker error then if you've found it in an include file and included that file. So you need to find out which library it's in and link that with the program. On the other hand if it's a compiler error then you don't actually need to #include anything; just copy the prototype into your program.

    The usual way to find out which library a function is included in is to check the documentation for that function and it will tell you. Or it could be described in the header file. If not then you'll need to hope that someone else round here knows DevC++ or ask at the DevC++ forum on SourceForge.
     
  14. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28
    Last edited: Mar 22, 2010
  15. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Every process in Windows has a process ID; open Task Manager, switch to the Processes view and make sure the PID column is enabled.
    There's a kill program on MSDN. What I don't know is what it does internally; maybe it calls a system kill() library, or maybe it enumerates windows and finds process ID's (instances) from the main window.

    http://technet.microsoft.com/en-us/sysinternals/bb896683.aspx
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice