Unix/Linux Go Back    


Programming Post questions about C, C++, Java, SQL, and other programming languages here.

kill textrdit program

Programming


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 06-06-2006   -   Original Discussion by jeter
jeter jeter is offline
Registered User
 
Join Date: Jul 2005
Last Activity: 8 September 2009, 5:42 AM EDT
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
kill textrdit program

Dear All:
I use sun OS system and write a code in c as folloing
purpose kill textedit program,but i get some error
please give me a great help Thanks.

#include <stdlib.h>
int main()
{
const char cTestPrag[]=" kill -9 `ps -ef | grep textedit | grep -v "grep"| awk '{print $2}'| xargs` ";

system(cTestPrag);

return 0;
}
Sponsored Links
    #2  
Old Unix and Linux 06-06-2006   -   Original Discussion by jeter
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 16 November 2017, 8:38 AM EST
Location: NM
Posts: 11,238
Thanks: 570
Thanked 1,116 Times in 1,030 Posts

Code:
#include <stdlib.h>
int main()
{
   char cTestPrag[128]={0x0};
   
   sprintf(cTestPrag, "kill -9 `ps -ef | grep textedit | grep -v %cgrep%c| awk '{print $2}'` ",
       '"','"');
   system(cTestPrag);

   return 0;
}

Sponsored Links
    #3  
Old Unix and Linux 06-06-2006   -   Original Discussion by jeter
DreamWarrior DreamWarrior is offline
Registered User
 
Join Date: Oct 2003
Last Activity: 15 February 2013, 11:18 PM EST
Posts: 174
Thanks: 1
Thanked 7 Times in 6 Posts
More easily, just escape the quotes in the string.

const char cTestPrag[]=" kill -9 `ps -ef | grep textedit | grep -v \"grep\"| awk '{print $2}'| xargs` ";
    #4  
Old Unix and Linux 06-06-2006   -   Original Discussion by jeter
jeter jeter is offline
Registered User
 
Join Date: Jul 2005
Last Activity: 8 September 2009, 5:42 AM EDT
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by jim mcnamara
Code:
#include <stdlib.h>
int main()
{
   char cTestPrag[128]={0x0};
   
   sprintf(cTestPrag, "kill -9 `ps -ef | grep textedit | grep -v %cgrep%c| awk '{print $2}'` ",
       '"','"');
   system(cTestPrag);

   return 0;
}



Dear jim mcnamara
Could you explain the code to me because i can't understand them


thanks
Sponsored Links
    #5  
Old Unix and Linux 06-06-2006   -   Original Discussion by jeter
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 16 November 2017, 8:38 AM EST
Location: NM
Posts: 11,238
Thanks: 570
Thanked 1,116 Times in 1,030 Posts
You cannot imbed " in a quoted string. You can escape them \" (which linters - code checkers - usually complain about), or you can use sprintf to place them in the string as single characters.

man sprintf
Sponsored Links
    #6  
Old Unix and Linux 06-07-2006   -   Original Discussion by jeter
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
 
Join Date: Mar 2005
Last Activity: 10 January 2017, 8:10 AM EST
Location: classification algos
Posts: 3,215
Thanks: 19
Thanked 31 Times in 28 Posts
what is the need for quoting grep as "grep" ?

is that going to make any difference ? It won't.
Sponsored Links
    #7  
Old Unix and Linux 06-07-2006   -   Original Discussion by jeter
grumpf grumpf is offline
Registered User
 
Join Date: May 2006
Last Activity: 24 October 2008, 11:54 AM EDT
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
maybe its not working on sun but whats about 'killall' ?
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Kill a running program? petel1 UNIX for Dummies Questions & Answers 3 05-26-2010 08:05 AM
Kill the running program akhtar.bhat Shell Programming and Scripting 1 12-26-2008 07:48 AM
Trying to kill a program via help command. TiznaraN Shell Programming and Scripting 5 04-22-2008 01:57 PM
kill multiple instances of the same program ipzig Shell Programming and Scripting 12 12-17-2007 02:42 AM
C program to kill root processes TioTony Programming 8 07-25-2003 12:16 AM



All times are GMT -4. The time now is 05:28 PM.