LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-22-2009, 06:52 AM   #1
ginda
Member
 
Registered: Mar 2004
Distribution: SUSE8.2, 9.2, Knoppix
Posts: 323

Rep: Reputation: 31
how to rename an already running script/process


Is it possible to rename a process that is currentley running i.e. from "batch.sh" to "donotkill" etc

Thanks in advance
 
Old 12-22-2009, 07:46 AM   #2
GooseYArd
Member
 
Registered: Jul 2009
Location: Reston, VA
Distribution: Slackware, Ubuntu, RHEL
Posts: 183

Rep: Reputation: 46
Quote:
Originally Posted by ginda View Post
Is it possible to rename a process that is currentley running i.e. from "batch.sh" to "donotkill" etc

Thanks in advance
If you're using perl, you can say:

$0 = "new_name"

not sure about bash, but I suspect its similar

.andy
 
Old 12-22-2009, 07:52 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Processes do not have names; they have numbers (= process IDs, PIDs) and one of their properties is a string containing the command line they were started with (like batch.sh). It is, of course, not possible to change the command they were started with. Kernel space programming could, possibly, be used to change the string but that would be very messy.
 
Old 12-22-2009, 08:37 AM   #4
ginda
Member
 
Registered: Mar 2004
Distribution: SUSE8.2, 9.2, Knoppix
Posts: 323

Original Poster
Rep: Reputation: 31
Thanks for both of your great replies.

Just another quick questions:

1. Could you please provide me with some examples of change the name of an already running process?

2. Does these examples work with any process that is running in a linux os?

Thanks again in advance, really appriciate all your help.
 
Old 12-23-2009, 06:38 AM   #5
GooseYArd
Member
 
Registered: Jul 2009
Location: Reston, VA
Distribution: Slackware, Ubuntu, RHEL
Posts: 183

Rep: Reputation: 46
Quote:
Originally Posted by ginda View Post
Thanks for both of your great replies.

Just another quick questions:

1. Could you please provide me with some examples of change the name of an already running process?

2. Does these examples work with any process that is running in a linux os?

Thanks again in advance, really appriciate all your help.
sure-

put this into a file called, say "old_name.pl"

#!/usr/bin/perl
print "process name for pid $$ is $0";
sleep(10);
$0="new_name.pl";
print "Check ps aux, new name for $$ is $0";
sleep(10);

then chmod +x old_name.pl
./old_name.pl

.andy
 
Old 07-27-2021, 12:06 PM   #6
auntchiladaz
LQ Newbie
 
Registered: Jul 2021
Posts: 1

Rep: Reputation: Disabled
the bash builtin command exec enables one to name a process.

for example, the shell login process on macOS uses exec -la to name the
user's login shell to -bash

Code:
login  -pfl  <username>  /bin/bash  -c  exec  -la  bash $SHELL
see
Code:
$ help exec

Last edited by auntchiladaz; 07-27-2021 at 12:08 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script : Kill a running process when another process starts ashmew2 Linux - General 3 08-20-2008 03:47 AM
running script after boot process in linux saheelahamed Linux - Software 1 06-11-2008 03:10 AM
Stop process while running script azazel11998 Programming 1 07-01-2007 04:12 AM
Script to see if a process ir running, if not start it ncsuapex Programming 4 07-03-2005 01:27 PM
[script] check for a running process mikshaw Linux - Software 2 01-13-2004 08:33 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration