![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| 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 11: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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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; } |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
Quote:
Dear jim mcnamara Could you explain the code to me because i can't understand them thanks |
|
#5
|
|||
|
|||
|
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
|
|||
|
|||
|
what is the need for quoting grep as "grep" ?
is that going to make any difference ? It won't. |
|
#7
|
|||
|
|||
|
maybe its not working on sun but whats about 'killall' ?
|
|||
| Google The UNIX and Linux Forums |