Home Man
Search
Today's Posts
Register

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

kill textrdit program

Tags
programming

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 06-06-2006
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;
}
# 2  
Old 06-06-2006
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;
}

# 3  
Old 06-06-2006
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 06-06-2006
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
# 5  
Old 06-06-2006
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
# 6  
Old 06-07-2006
what is the need for quoting grep as "grep" ?

is that going to make any difference ? It won't.
# 7  
Old 06-07-2006
maybe its not working on sun but whats about 'killall' ?
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Kill a program from bash arpagon UNIX for Dummies Questions & Answers 7 07-25-2014 01:34 PM
Kill an specific process ID using the KILL and GREP commands enriquegm82 Shell Programming and Scripting 6 02-06-2013 06:16 PM
Kill a running program? petel1 UNIX for Dummies Questions & Answers 3 05-26-2010 07:05 AM
Kill shell script when host program not running/disk unmounted pcwiz Shell Programming and Scripting 2 10-02-2009 10:04 AM
Kill the running program akhtar.bhat Shell Programming and Scripting 1 12-26-2008 06:48 AM
Kill a process without using kill command sudhamacs Shell Programming and Scripting 0 10-01-2008 05:19 PM
Trying to kill a program via help command. TiznaraN Shell Programming and Scripting 5 04-22-2008 12:57 PM
kill multiple instances of the same program ipzig Shell Programming and Scripting 12 12-17-2007 01:42 AM
When kill doesnt work, how to kill a process ? VijayHegde UNIX for Advanced & Expert Users 3 05-12-2006 04:24 PM
C program to kill root processes TioTony Programming 8 07-24-2003 11:16 PM


All times are GMT -4. The time now is 06:02 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password