The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Trying to kill a program via help command. TiznaraN Shell Programming and Scripting 5 04-22-2008 09:57 AM
kill multiple instances of the same program ipzig Shell Programming and Scripting 12 12-16-2007 10:42 PM
KILL PID, intern should kill another PID. rkrgarlapati Shell Programming and Scripting 4 10-17-2006 04:47 AM
When kill doesnt work, how to kill a process ? VijayHegde UNIX for Advanced & Expert Users 3 05-12-2006 01:24 PM
C program to kill root processes TioTony High Level Programming 8 07-24-2003 08:16 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-06-2006
Registered User
 

Join Date: Jul 2005
Posts: 11
Stumble this Post!
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;
}
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-06-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,794
Stumble this Post!
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;
}
Reply With Quote
  #3 (permalink)  
Old 06-06-2006
Registered User
 

Join Date: Oct 2003
Posts: 69
Stumble this Post!
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` ";
Reply With Quote
  #4 (permalink)  
Old 06-06-2006
Registered User
 

Join Date: Jul 2005
Posts: 11
Stumble this Post!
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
Reply With Quote
  #5 (permalink)  
Old 06-06-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,794
Stumble this Post!
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
Reply With Quote
  #6 (permalink)  
Old 06-07-2006
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,546
Stumble this Post!
what is the need for quoting grep as "grep" ?

is that going to make any difference ? It won't.
Reply With Quote
  #7 (permalink)  
Old 06-07-2006
Registered User
 

Join Date: May 2006
Posts: 95
Stumble this Post!
maybe its not working on sun but whats about 'killall' ?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:24 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0