/*
* Copyright (c) 1997-1999 Red Hat, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include <unistd.h>
int main(int argc, char ** argv) {
if (argc<2) return 1; execvp(argv[1], argv + 2); return 1; }
Компилировать так:
gcc doexec.c -o doexec
Использовать так:
./doexec /usr/bin/perl new_name -e 'while(){}'
И теперь если в другой консоли посмотреть имя процесса, то оно будет вот такое:
root 32576 92.0 0.0 100468 1556 pts/0 R+ 03:49 0:06 new_name -e while(){}
Теперь немного теории о том, как это работает:
The execv() and execvp() functions provide an array of pointers to null-terminated strings that represent the argument list available to the new program. The first argument, by convention, should point to the filename associated with the file being executed. The array of pointers must be terminated by a NULL pointer.
Одно прошу - не спрашивайте, зачем мне это понадобилось :)))
No comments :
Post a Comment
Note: only a member of this blog may post a comment.